I want to get the Base64 of an image from Gallery. I am getting the file path of the image using foreign code(android) but when I tried to get Base64 I am getting
" java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media uid=10099 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()"
this error. I already given the permission for reading external storage.
This is my code
Bitmap bitmap = BitmapFactory.decodeFile(FilePath);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, bos);
byte[] imagedata = bos.toByteArray();
String imageuploaded=Base64.encode(imagedata, Base64.DEFAULT);
Did you give permissions in the manifest file only or did you request permissions at runtime as well (e.g. ActivityCompat.requestPermissions())?
Because starting from Android 5.0 you have to request them at runtime as well.
Thanks for your reply, I tried with the below code
final android.app.Activity context = com.fuse.Activity.getRootActivity();
ActivityCompat.requestPermissions(context,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
and I got the below given error message :
java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=1, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.apps.fuse.filedialog/com.apps.fuse.filedialog.FuseFileDialog}: java.lang.NullPointerException: Attempt to read from field 'int com.fuse.PermissionsRequest.requestID' on a null object reference
Also I tried with this one
Permissions.Request(Permissions.Android.READ_EXTERNAL_STORAGE).Then(OnPermissionsPermitted,OnPermissionsRejected) as runtime permission
and I got the same error
java.lang.SecurityException: Permission Denial:requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
Unable to decode stream: java.io.FileNotFoundException: /external/images/media/93
Hmm, please check the below stackoverflow post and see if it helps: