Android Marshmallow 6.0,通过 intent 打开画廊说没有应用可以执行该操作

Android Marshmallow 6.0, opening gallery via intent says No apps to perform the action

我正在尝试使用 Android 6.0 在 Nexus 7 上打开图库。它没有内置图库,但有 Google Photos 应用程序。

我正在使用以下代码打开图库:

    Intent i = new intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Always show the chooser (if there are multiple options available)
    startActivityForResult(Intent.createChooser(i, "Select Picture"), PICK_IMAGE_REQUEST);

以上代码在6.0以下的所有版本中都运行良好。并且请注意,我已经在使用 运行 时间权限来访问图库,并已授予访问图库/或外部存储的权限。

现在,当执行代码时,我得到一个透明屏幕,标题为 "Select Picture",中间有一个文本 没有应用程序可以执行此操作。

现在我该怎么做才能挑选或选择图像并在我的应用程序中使用。

感谢任何帮助。

谢谢

我没有足够的积分,不允许发表评论。不过这里只是一个建议,如果直接传Intent呢?像这样:

startActivityForResult(i, PICK_IMAGE_REQUEST);

使用这行代码而不是你所做的

Intent i = new intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, PICK_IMAGE_REQUEST);

I am using the following code to open the gallery

该代码与 "gallery" 无关。该代码请求从特定内容集合中挑选一段内容。设备上可能有零个、一个或多个活动支持该 Intent 结构。

The above code works well in all the versions below 6.0

仅适用于恰好具有满足该 Intent 结构的一项或多项活动的设备。

Now what do I do to pick or choose image and use in my app.

Intent i = new intent(Intent.ACTION_GET_CONTENT).setType("image/*");

// use PackageManager to see if there is anything that supports this
// Intent structure, or just blindly make the following call and handle
// the ActivityNotFoundException

startActivityForResult(i, PICK_IMAGE_REQUEST);

I am using this code , so that only gallery opens and not any other option to pick image

您的代码中没有任何内容将其限制为 "gallery"。