save the image to the gallery in android -
how can save image camera take gallery? have code doesn't save image
private file createimagefile() throws ioexception { // create image file name string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date()); string imagefilename = "jpeg_" + timestamp + "_"; file storagedir = getexternalfilesdir(environment.directory_pictures); file image = file.createtempfile( imagefilename, /* prefix */ ".jpg", /* suffix */ storagedir /* directory */ ); // save file: path use action_view intents mcurrentphotopath = image.getabsolutepath(); return image; }
and use thise 1
private void galleryaddpic() { intent mediascanintent = new intent(intent.action_media_scanner_scan_file); file f = new file(mcurrentphotopath); uri contenturi = uri.fromfile(f); mediascanintent.setdata(contenturi); this.sendbroadcast(mediascanintent); }
but doesn't have positive result, in manifest use permission
<uses-permission android:name="android.permission.write_external_storage" android:maxsdkversion="18"/>
from android version m , above, runtime permission required dangerous permission - https://developer.android.com/guide/topics/permissions/requesting.html#normal-dangerous
public void checkpermissiongranted() { if (build.version.sdk_int >= 23) { if (!(checkselfpermission(manifest.permission.read_external_storage) == packagemanager.permission_granted)) { requestpermissions(new string[]{manifest.permission.read_external_storage}, 0); } } } @override public void onrequestpermissionsresult(int requestcode, string[] permissions, int[] grantresults) { super.onrequestpermissionsresult(requestcode, permissions, grantresults); if (!(grantresults[0] == packagemanager.permission_granted)) { log.d(tag, "storage permission not granted"); } else { // permission granted - resume } }
Comments
Post a Comment