AIDE android11 接收 QQ 其他方法打开文件


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mycompany.myapp2" >
	<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
    
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            intent-filter>
			
			<intent-filter>
                <action
                    android:name="android.intent.action.VIEW" />
                <action
                    android:name="android.intent.action.EDIT" />
                <category
                    android:name="android.intent.category.DEFAULT" />
                <category
                    android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="file" />
                <data android:scheme="content" />
                <data
                    android:mimeType="application/x-javascript" />
                <data android:mimeType="text/plain" />
            intent-filter>
			
        activity>
    application>

manifest>
package com.mycompany.myapp2;

import android.app.*;
import android.os.*;
import android.content.*;
import android.provider.*;
import android.net.*;
import java.io.*;
import android.graphics.*;
import android.widget.*;
import android.database.*;

public class MainActivity extends Activity 
{
	private ImageView tp;
	private TextView xx;
	private int REQUEST_MANAGE_EXTERNAL_STORAGE;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		tp=findViewById(R.id.tp);
		xx=findViewById(R.id.xx);
		Uri uri = getIntent().getData();
		if (uri != null) {
			try {
				InputStream inputStream = getContentResolver().openInputStream(uri);
				BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
				StringBuilder stringBuilder = new StringBuilder();
				String line;
				while ((line = reader.readLine()) != null) {
					stringBuilder.append(line);
					stringBuilder.append("\n");
				}
				reader.close();
				inputStream.close();

				String fileContent = stringBuilder.toString();
				xx.setText(fileContent);
				// 处理文件内容

			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}
    // 处理权限请求结果
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == REQUEST_MANAGE_EXTERNAL_STORAGE)
		{
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
			{
				if (Environment.isExternalStorageManager())
				{
					// 权限已经被授予,可以进行相关操作
					// ...
				}
				else
				{
					// 权限被拒绝,无法进行相关操作
					// ...
				}
			}
		}
	}
	
	private void du(){
		try
		{
			String s="";
			String lj="com.tencent.mobileqq/Tencent/QQ_Images/QQEditPic/qq_pic_merged_1674010957251.jpg%";
			//String externalStoragePath = getExternalFilesDir(null).getAbsolutePath();
			//String imagePath = externalStoragePath + "/Android/data/"+lj;
			//Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
			//String lj="/storage/emulated/0/Android/data/com.tencent.mobileqq/Tencent/QQ_Images/QQEditPic/qq_pic_merged_1674010957251.jpg";
			//FileInputStream fs = new FileInputStream(lj);
			//Bitmap bitmap = BitmapFactory.decodeStream(fs);
			Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
			String selection = MediaStore.Images.Media.RELATIVE_PATH + " LIKE ?";
			String[] selectionArgs = new String[]{"%Android/data/"+lj};

			Cursor cursor = getContentResolver().query(contentUri, null, selection, selectionArgs, null);
			if (cursor != null && cursor.moveToFirst()) {
				int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
				String imagePath = cursor.getString(columnIndex);

				File imageFile = new File(imagePath);
				if (imageFile.exists()) {
					Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
					tp.setImageBitmap(bitmap);
				}
				cursor.close();
			}
			
			
		    //tp.setImageBitmap(bitmap);
		}catch(Exception e){
			
		}
	}
}

注意 targetSdkVersion 是 29
不是说修改27修改29就行
QQ群 647162429

你可能感兴趣的:(笔记,android)