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

<?xml version="1.0" encoding="utf-8"?>
<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"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
		android:resizeableActivity = "true">
        <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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值