我想使用默认相机拍摄图像并将其保存在内部存储中。我希望在sdcard / camera_app /中保存图像,并将文件名保存为sdcard / camera_app中的cam_image.jpg,并在imageview页面中显示捕获图像。此代码适用于Android M,但它不适用于API级别24(牛轧糖)或以上。
给我一个错误消息 file:///sdcard/camera_app/cam_image.jpg通过ClipData.Item.getUri()
在app之外暴露关于这个的任何想法?谢谢你的意见
这是代码
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));
}
这是我的登录,我打印异常
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()