0

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()
  • Which statement causes the error? – greenapps Jan 06 '18 at 11:03
  • `"sdcard/camera_app/cam_image.jpg";`. That should be `"/sdcard/camera_app/cam_image.jpg";`. – greenapps Jan 06 '18 at 11:03
  • Please remove tne android-studio tag. It has nothing to do with your problem. – greenapps Jan 06 '18 at 11:04
  • `Log.d("MainActivity"," saved"); Toast.makeText(getApplicationContext()," saved ",Toast.LENGTH_SHORT).show();`. I wonder what you have in mind with those messages. The user did not yet take a picture. And can even cancel the operation. – greenapps Jan 06 '18 at 11:06
  • `exposed beyond app through ClipData.Item.getUri()`. Where is that code? – greenapps Jan 06 '18 at 11:07
  • Is it that you have an exception in creating the intent? And that you are talking about the log and toast in that catch block? Please confirm! – greenapps Jan 06 '18 at 11:12
  • my code is work till _android M_ , but in _Android nougat_ at this line app crashed `startActivityForResult(camera_intent,CAM_REQUEST);` and error message i got in Log is **file:///sdcard/camera_app/cam_image.jpg exposed beyond app through ClipData.Item.getUri()** – Pritesh Vishwakarma Jan 06 '18 at 11:30
  • Your app does not have to crash if indeed you catched the exception. – greenapps Jan 06 '18 at 12:27
  • I SOLVED MY PROBLEM , THANX FOR YOU TIME :D – Pritesh Vishwakarma Jan 06 '18 at 13:01

0 Answers0