Android: gallery intent returns resultCode == RESULT_CANCELED

I am starting to collect the image from the gallery, but the target always returns using resultcode RESULT_CANCELED. I tried a lot of different codes, but nothing helps me think, maybe something is missing for me, for example, something interfered with the Android manifest?

My code is:

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

Thank you for your help;)

+6
android android-intent gallery
source share
2 answers

OK, so I solved it. My problem turned out to be that the onActivityResult () method is called before the Pebble project is finished. I found a solution: onActivityResult () called prematurely

Basically, I indicated activity as "singleTask" in the manifest. Changing it to "singleTop" solved it for me.

+16
source share

It saved my life! \ 0 /

Android: launchMode = "SingleTop"

+1
source share

All Articles