I am trying to pick the image from the gallery and it is working fine in below android 7.1 but from android 7.1 it is not working for me. How to fix the same. This the code which I tried :
public void LaunchGalleryView() {
mFileUri = null;
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_CODE_GALLERY);
}
This is the code in onActivityResult():
case REQUEST_CODE_GALLERY:
if (data == null) {
return;
}
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
File file = new File(picturePath);
mFileUri = FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", file);
performCrop();
break;
How to fix the same please help me.
This is the error log:
12-28 05:13:30.085 13533-13533/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.welldoc.platform.android.cyan, PID: 13533 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/0/1/mediakey:/local%3Aefc38517-5fd9-4b57-afbf-6329e508fb66/ORIGINAL/NONE/1646850308 flg=0x1 clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/0/1/mediakey%3A%2Flocal%253Aefc38517-5fd9-4b57-afbf-6329e508fb66/ORIGINAL/NONE/1646850308} }} to activity {com.welldoc.platform.android.cyan/com.welldoc.platform.android.ui.profile.ProfileDetailsEditActivity}: java.lang.NullPointerException at android.app.ActivityThread.deliverResults(ActivityThread.java:4324) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4367) at android.app.ActivityThread.-wrap19(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.NullPointerException at java.io.File.(File.java:282) at com.welldoc.platform.android.ui.profile.ProfileDetailsEditActivity.onActivityResult(ProfileDetailsEditActivity.java:1059) at android.app.Activity.dispatchActivityResult(Activity.java:7235) at android.app.ActivityThread.deliverResults(ActivityThread.java:4320) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4367) at android.app.ActivityThread.-wrap19(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)