Captured image not appearing in gallery

luwionline

I'm using the camera intent to captured images. But it's not showing when I check in on the gallery..

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());

Intent intent_cam = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);                    
File imagesFolder = new File(Environment.getExternalStorageDirectory() + File.separator + "App Photos");

Intent mediaScan = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

if (!imagesFolder.exists()) {       

imagesFolder.mkdirs();          
File image = new File(imagesFolder, "App_" + timeStamp + ".png");
Uri uriSavedImage = Uri.fromFile(image);         
intent_cam.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);    
mediaScan.setData(uriSavedImage);
getActivity().sendBroadcast(mediaScan);
startActivityForResult(intent_cam, 0);           
}

else if (imagesFolder.exists()) {

File image = new File(imagesFolder, "App_" + timeStamp + ".png");
Uri uriSavedImage = Uri.fromFile(image);
intent_cam.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
mediaScan.setData(uriSavedImage);
getActivity().sendBroadcast(mediaScan);
startActivityForResult(intent_cam, 0);    

}

Manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

And is it true that the sendBroadcast no longer works in API 19. (4.4)? Android How to use MediaScannerConnection scanFile

CommonsWare

You are invoking the scan request before the picture has been captured. Recall that startActivityForResult() is asynchronous. Put your sendBroadcast() call in onActivityResult(), which will be triggered when the camera activity returns control to you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related