小编Vel*_*eve的帖子

Android Gallery 总是将 RESULT_CANCELED 返回给 onActivityResult

首先,这不是过早返回结果代码的常见问题。在这种情况下,只有在图库中选择了一个项目后才会返回它。

在我的测试用例中,我使用以下代码调用 Gallery:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,  SELECT_PICTURE);
Run Code Online (Sandbox Code Playgroud)

在 onActivityResult 中有:

if (resultCode == Activity.RESULT_OK) {
    if (requestCode == SELECT_PICTURE) {
        Uri selectedImageUri = data.getData();
        pathText.setText(selectedImageUri.getPath());
    }
} else {
    pathText.setText("Result not OK - code is " + resultCode);
}
Run Code Online (Sandbox Code Playgroud)

pathText 只是我用来在测试用例中显示结果的 TextView。在实际应用中,路径有不同的用途。

如果我使用 ACTION_PICK 而不是 _GET_CONTENT,我会立即收到其他人报告的失败。清单中没有 launchMode 标签(一些帖子在该区域提出了问题)。

也许这里有线索。在 Toshiba Thrive 上,使用图库、文件管理器或鱼缸照片图库不会出现此错误。在 Kindle Fire 上,Quickoffice 也能够正确返回图像路径。该错误仅出现在 Kindle 的内置图库中。在“Motorola Droid(2.3.4) , HTC EVO (2.3)”上也观察到了该错误。

请问,如何以适用于所有这些设备的方式从图库中获取图像路径?

android image gallery android-intent

2
推荐指数
1
解决办法
2431
查看次数

标签 统计

android ×1

android-intent ×1

gallery ×1

image ×1