简体   繁体   English

intent.resolveActivity 在 API 30 中的 android.intent.action.OPEN_DOCUMENT 上返回 null

[英]intent.resolveActivity returns null on android.intent.action.OPEN_DOCUMENT in API 30

I am having problem to pick a pdf file.我在选择 pdf 文件时遇到问题。 Before, the targetSdk is 29 and it's working fine but when I updated it to 30, device with Android 11 and above can't open the file manager to pick the pdf file.之前,targetSdk 是 29 并且工作正常,但是当我将其更新到 30 时,Android 11 及更高版本的设备无法打开文件管理器来选择 pdf 文件。 Device with version below Android 11 is working fine.版本低于 Android 11 的设备运行良好。 This is the code to create the Intent:这是创建 Intent 的代码:

Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT");
intent.addCategory("android.intent.category.OPENABLE");
intent.setType("application/pdf");

and this is the code to launch the intent :这是启动意图的代码:

boolean canBeLaunched = false;
if (intent.resolveActivity(fragment.getActivity().getPackageManager()) != null) {
    canBeLaunched = true;
    fragment.startActivityForResult(intent, requestCode);
}

On debug, intent.resolveActivity returns null on Android 11 and above.在调试时,intent.resolveActivity 在 Android 11 及更高版本上返回 null。

in Android 11 were made some changes in package visbility, some info HERE and HERE在 Android 11 中对包的可见性进行了一些更改,一些信息HEREHERE

note that resolveActivity should return package name of app, which can handle this intent.请注意, resolveActivity应该返回可以处理此意图的应用程序的包名称。 Thats against freshly introduced rules and new policy as above这违反了上述新引入的规则和新政策

instead try to run startActivityForResult strictly without your if and wrap it in try { ... } catch (ActivityNotFoundException ex){}而是尝试在没有if的情况下严格运行startActivityForResult并将其包装在try { ... } catch (ActivityNotFoundException ex){}

boolean canBeLaunched;
try {
    fragment.startActivityForResult(intent, requestCode);
    canBeLaunched = true
} catch (ActivityNotFoundException ex){
    canBeLaunched = false
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到用于处理意图的活动{act = android.intent.action.OPEN_DOCUMENT cat = [android.intent.category.OPENABLE] typ = / *} - No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT cat=[android.intent.category.OPENABLE] typ=/* } "intent.resolveActivity(getPackageManager()) 到底在做什么?" - What exactly is intent.resolveActivity(getPackageManager()) doing? 为什么 intent.resolveActivity(getPackageManager()) 返回 null 即使有 Activity 来处理它? - Why does intent.resolveActivity(getPackageManager()) return null even though there is Activity to handle it? 如何在 Android Pie 中使用 Intent.ACTION_OPEN_DOCUMENT - How to use Intent.ACTION_OPEN_DOCUMENT in Android Pie 使用 Intent.ACTION_OPEN_DOCUMENT 从特定文件夹打开文件 - Open file from specific folder with Intent.ACTION_OPEN_DOCUMENT Android Intent.getStringExtra()在Broadcastreceiver中返回null - Android Intent.getStringExtra() returns null in Broadcastreceiver Android Intent Bundle 传递返回始终为 null - Android Intent Bundle passing returns always null 使用Intent.ACTION_OPEN_DOCUMENT_TREE将文件写入目录 - Write file to directory using Intent.ACTION_OPEN_DOCUMENT_TREE resolveActivity(getPackageManager()) != null 返回 null - resolveActivity(getPackageManager()) != null returns null 如何为 ACTION_OPEN_DOCUMENT 意图实现自定义 MIME 类型? - How to implement a custom MIME type for ACTION_OPEN_DOCUMENT intent?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM