安卓:画廊意图返回结果code == RESULT_CANCELED [英] Android: Gallery intent returning resultCode == RESULT_CANCELED

查看:130
本文介绍了安卓:画廊意图返回结果code == RESULT_CANCELED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始的意图,选择从画廊的照片,但目的总是与结果code RESULT_CANCELED返回。我已经尝试了不同的code很多,但没有什么帮助至极让我觉得也许我失去了一些东西,喜欢把什么东西在活动中的Andr​​oid清单?

I'm starting an intent to pick a picture from the gallery but the intent always returns with the resultcode RESULT_CANCELED. I have tried alot of different code but nothing helps wich makes me think maybe I am missing something, like putting something in the activity in the Android manifest?

我的code:

// The Intent
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 0);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK){
        Uri targetUri = data.getData();
        Bitmap bitmap;
        try {
            bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
            profileImage.setImageBitmap(bitmap);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}

将为AP preciate一定的帮助;)

Would appreciate some help ;)

推荐答案

行,所以我解决了这个。我的问题竟然是该onActivityResult()方法被调用的库意图已经完成了。我发现sollution这里:<一href="http://stackoverflow.com/questions/3354955/onactivityresult-called-$p$pmaturely">onActivityResult()所谓的prematurely

OK so I solved this. My problem turned out to be that the onActivityResult() method was being called before the Gallery Intent had finished. I found the sollution here: onActivityResult() called prematurely

基本上,我已经指定的活动为singleTask的清单。 将其更改为singleTop解决了这个问题对我来说。

Basically, I had specified the activity to be "singleTask" in the manifest. Changing it to "singleTop" solved it for me.

这篇关于安卓:画廊意图返回结果code == RESULT_CANCELED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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