android - BitmapFactory decode returns null -
i dealing weird thing in android now. code used work till few days ago stops working. selecting image gallery , want bitmap object of it. code:
imgdecodablestring = "/storage/emulated/0/dcim/camera/img_20160114_141351594.jpg" bitmap decodedbitmap = bitmapfactory.decodefile(imgdecodablestring); log.d(constants.tag, "decodedbitmap: " + decodedbitmap);
bitmap null (used work) , don't wrong. didn't changed code. had problem? thank you.
i have permissions:
<uses-permission android:name="android.permission.read_external_storage"/> <uses-permission android:name="android.permission.write_external_storage"/>
if (checkpermission(youractivity.this, manifest.permission.write_external_storage)) { // have permission go ahead string imgdecodablestring = "/storage/emulated/0/dcim/camera/img_20160114_141351594.jpg"; if(new file(imgdecodablestring).exists()){ bitmap decodedbitmap = bitmapfactory.decodefile(imgdecodablestring); log.d("tag", "decodedbitmap: " + decodedbitmap);} } else { // not have permission go request runtime permissions requestpermission(youractivity.this, manifest.permission.write_external_storage, request_runtime_permission); } @override public void onrequestpermissionsresult(int permsrequestcode, string[] permissions, int[] grantresults) { switch (permsrequestcode) { case request_runtime_permission: { if (grantresults.length > 0 && grantresults[0] == packagemanager.permission_granted) { } else { // not have permission show toast. } return; } } } public void requestpermission(activity thisactivity, string permission, int code) { if (contextcompat.checkselfpermission(thisactivity, permission) != packagemanager.permission_granted) { if (activitycompat.shouldshowrequestpermissionrationale(thisactivity, permission)) { } else { activitycompat.requestpermissions(thisactivity, new string[]{permission}, code); } } } public boolean checkpermission(activity context, string permission) { if (contextcompat.checkselfpermission(context, permission) == packagemanager.permission_granted) { return true; } else { return false; } }
in androidmainfest
<uses-permission android:name="android.permission.read_external_storage"/> <uses-permission android:name="android.permission.write_external_storage"/>
Comments
Post a Comment