java - Check SD Card after Saving Image (Android) -
i have intent when complete, saves image /sdcard/aperture. while image save, not show image saved. problem? tried using scan broadcast in on activity result causes crash, , not scan image.
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if (requestcode == settings_request && resultcode == activity.result_ok) { mediafragment content = (mediafragment) getfragmentmanager().findfragmentbyid(com.marlonjones.aperture.r.id.content_frame); if (content != null) content.reload(); reloadnavdraweralbums(); } if (requestcode == new_picture) { // return file upload if (resultcode == activity.result_ok) { uri uri = null; if (data != null) { uri = data.getdata(); } if (uri == null && mcamerafilename != null) { uri = uri.fromfile(new file(mcamerafilename)); } } } } final private int request_code_ask_permissions = 123; int currentapiversion = android.os.build.version.sdk_int; public void camera(menuitem menu) { if (android.os.build.version.sdk_int >= build.version_codes.m) { int hascamerapermission = checkselfpermission(manifest.permission.camera); if (hascamerapermission != packagemanager.permission_granted) { requestpermissions(new string[]{manifest.permission.camera}, request_code_ask_permissions); return; } intent intent = new intent(); intent.setaction(mediastore.action_image_capture); date date = new date(); dateformat df = new simpledateformat("-mm-ss"); string newpicfile = "ph" + df.format(date)+".jpg"; string outpath = "/sdcard/aperture/" + newpicfile; file outfile = new file(outpath); mcamerafilename = outfile.tostring(); uri outuri = uri.fromfile(outfile); intent.putextra(mediastore.extra_output, outuri); startactivityforresult(intent, new_picture); } else{ intent intent = new intent(); intent.setaction(mediastore.action_image_capture); date date = new date(); dateformat df = new simpledateformat("-mm-ss"); string newpicfile = "ph" + df.format(date) + ".jpg"; string outpath = "/sdcard/aperture/" + newpicfile; file outfile = new file(outpath); mcamerafilename = outfile.tostring(); uri outuri = uri.fromfile(outfile); intent.putextra(mediastore.extra_output, outuri); startactivityforresult(intent, new_picture);} }
impression uses mediascannerconnection in places believe. it's more modern version of using scanner intent. tells when scanning complete , gives new uri (or null if file removed media database).
mediascannerconnection.scanfile(this, new string[] { filepath }, null, new mediascannerconnection.onscancompletedlistener() { @override public void onscancompleted(string path, uri uri) { log.i("externalstorage", "scanned " + path + ":"); log.i("externalstorage", "-> uri=" + uri); } });
you'd want reload media , albums after scanning complete.
Comments
Post a Comment