Skip to content Skip to sidebar Skip to footer

Why Can't I Upload A Picture From Gallery In My Android App, If The Picture Was Taken With The Camera App From Android?

I want to upload an image from gallery and show it on my Android app. This works fine if I select an image from the screenshot folder for example. But when I select an image from t

Solution 1:

Make sure you have give run time permission to choose image from gallery and permissions in the manifest.

Use android:requestLegacyExternalStorage="true" in the manifest also.

Then for opening the gallery use this code:

Intentintent=newIntent();
                    intent.setType("image/*");
                    intent.setAction("android.intent.action.PICK");
                    startActivityForResult(intent, PICK_IMAGE_REQUEST);

In onActivityResult :

if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK
                && data != null && data.getData() != null) {  
            mImageUri = data.getData();
            //Use glide for better result
            Glide.with(this).load(mImageUri).into(mImageView);
         }

Solution 2:

In my opinion, these problems can be solved by ImagePicker Libraries such as Ucrop. Ucrop Library For Android

Make sure you have Runtime permission Handled. For easier permission handling you can use Dexter Dexter

Make sure u have External Storage Read permission in your manifest file. You may also require both Read/Write permission if you want to take image from camera.

<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE"/><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Note: for android version above Pie paste these attributes in application tag in manifest.xml :

<applicationandroid:preserveLegacyExternalStorage="true"android:requestLegacyExternalStorage="true"... >
...
...
</application>

Post a Comment for "Why Can't I Upload A Picture From Gallery In My Android App, If The Picture Was Taken With The Camera App From Android?"