I want to use default camera for capture image and save it in internal storage. I want save image in sdcard/camera_app/ and save filename as cam_image.jpg in sdcard/camera_app/ also display capture image in imageview page. this code work till Android M , but it not work in API level 24 ( Nougat ) or Above.
Give me an Error Message file:///sdcard/camera_app/cam_image.jpg exposed beyond app through ClipData.Item.getUri()
any idea about this ?? thanks in adavance
Here is Code
btnCapturePicture.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
try
{
Intent camera_intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file=getFile();
camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(camera_intent,CAM_REQUEST);
Log.d("MainActivity"," saved");
Toast.makeText(getApplicationContext()," saved ",Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Log.d("MainActivity"," error = "+e.getMessage().toString());
Toast.makeText(getApplicationContext()," error = "+e.getMessage().toString(),Toast.LENGTH_SHORT).show();
}
//captureImage();
}
});
private File getFile()
{
File folder=new File("sdcard/camera_app");
if(!folder.exists())
{
folder.mkdir();
}
File image_file=new File(folder,"cam_image.jpg");
return image_file;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
String path="sdcard/camera_app/cam_image.jpg";
imgPreview.setImageDrawable(Drawable.createFromPath(path));
}
here is my Log in which i print exception
01-06 16:24:22.646 14907-14907/android.selfielife.com.camera E/MainActivity: error = file:///sdcard/camera_app/cam_image.jpg exposed beyond app through ClipData.Item.getUri()
01-06 16:24:30.596 14907-14971/android.selfielife.com.camera D/AppTracker: App Event: stop
01-06 16:24:31.634 14907-14976/android.selfielife.com.camera D/AppTracker: App Event: start
01-06 16:24:34.470 14907-14907/android.selfielife.com.camera E/MainActivity: error = file:///sdcard/camera_app/cam_image.jpg exposed beyond app through ClipData.Item.getUri()