相关疑难解决方法(0)

Intent.resolveActivity 在 API 30 中返回 null

查看intent.resolveActivity != null 但启动 Intent 会引发 ActivityNotFound 异常,我在打开浏览器或具有深度链接的应用程序时写道:

private fun openUrl(url: String) {
    val intent = Intent().apply {
        action = Intent.ACTION_VIEW
        data = Uri.parse(url)
//        setDataAndType(Uri.parse(url), "text/html")
//        component = ComponentName("com.android.browser", "com.android.browser.BrowserActivity")
//        flags = Intent.FLAG_ACTIVITY_CLEAR_TOP + Intent.FLAG_GRANT_READ_URI_PERMISSION
    }
    val activityInfo = intent.resolveActivityInfo(packageManager, intent.flags)
    if (activityInfo?.exported == true) {
        startActivity(intent)
    } else {
        Toast.makeText(
            this,
            "No application can handle the link",
            Toast.LENGTH_SHORT
        ).show()
    }
}
Run Code Online (Sandbox Code Playgroud)

它不起作用。在 API 30 模拟器中找不到浏览器,而一个常见的解决方案有效:

private fun openUrl(url: String) {
    val intent …
Run Code Online (Sandbox Code Playgroud)

android android-manifest android-intent activitynotfoundexception android-11

56
推荐指数
5
解决办法
2万
查看次数

无法在 Android 11 上以编程方式拍照 - 意图返回取消状态

开始一个意图:

  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  CurrentFile = new File(getTempFileString());
  CurrentUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", CurrentFile);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, CurrentUri);
  intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
  startActivityForResult(intent, IMAGE_CAPTURE);
Run Code Online (Sandbox Code Playgroud)

曾经工作。现在不行了。我在意图之后开始的方法是:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
Run Code Online (Sandbox Code Playgroud)

resultCode以前是RESULT_OK,但现在RESULT_CANCELED

如果我停止检查 resultCode 并跳过它,我会发现照片不存在。

根据 CommonsWare 的评论,我提取了日志。在此操作期间生成的 654 行中,有四行似乎相关。

2020-10-12 11:03:04.301 1471-1763/? E/MediaProvider: Creating a non-default top level directory or deleting an existing one is not allowed!
2020-10-12 11:03:04.310 477-2112/? I/AppsFilter: interaction: PackageSetting{240e1c6 com.[my app package]/10151} -> PackageSetting{193734c com.android.camera2/10124} …
Run Code Online (Sandbox Code Playgroud)

java android android-11

3
推荐指数
1
解决办法
4346
查看次数