Android图库总是返回到RESULT_CANCELED的onActivityResult [英] Android Gallery always returns RESULT_CANCELED to onActivityResult

查看:2000
本文介绍了Android图库总是返回到RESULT_CANCELED的onActivityResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这不是它的结果$ C $返回c prematurely经常张贴问题。在这种情况下,一个项目库中的采摘之后才会返回。

First of all, this is NOT the frequently-posted problem where the result code is returned prematurely. In this case, it is returned only after an item is picked in the gallery.

在我的测试情况下,我把这个code画廊:

In my test case I call the Gallery with this code:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,  SELECT_PICTURE);

和在那里的onActivityResult是:

and in onActivityResult there is:

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);
}

pathText只是一个TextView我把在显示结果中的测试案例。在实际应用中有用于路径不同的用途。

pathText is just a TextView I put in to show the result in the test case. In the actual application there is a different use for the path.

如果我用ACTION_PICK代替_GET_CONTENT我得到其他人的报道立即失效。有在清单中没有launchMode标签(有的帖子建议在这方面的问题)。

If I use ACTION_PICK instead of _GET_CONTENT I get the immediate failure reported by others. There are no launchMode tags in the manifest (some posts have suggested problems in that area).

也许这里有一个线索。在东芝茁壮成长,这个错误不会出现,使用画廊,文件管理器,或鱼缸照片库。在Kindle Fire的,Quickoffice是也能够正确返回图像路径。该错误只出现在我在Kindle内置的画廊。该缺陷还对一个摩托罗拉Droid(2.3.4),HTC EVO(2.3)。

Maybe there is a clue here. On a Toshiba Thrive, this bug does not appear, using Gallery, File Manager, or Fish Bowl Photo Gallery. On Kindle Fire, Quickoffice is also able to return an image path correctly. The bug only appears for me on the Kindle's built-in Gallery. The bug was also observed on a "Motorola Droid(2.3.4) , HTC EVO (2.3)".

请,我怎么能得到一个图像路径从画廊回到上所有这些设备的工作方式?

Please, how can I get an image path back from the Gallery in a way that works on all these devices?

推荐答案

我认为,在默认情况下画廊不返回结果code,如果你不是在意向指定要返回结果code。您可以在指定的意图通过在code加入这个片段像这样返回结果code:

I think, by default gallery does not return result code if you not specify in the intent to return result code. You can specify in the intent to return result code by adding this snippet in your code like this:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra("return-data", true); //added snippet
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_PICTURE);

如果这篇文章可以帮助你,请注明这篇文章作为一个答案。

If this post helps you, please mark this post as an answer.

感谢。

这篇关于Android图库总是返回到RESULT_CANCELED的onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆