当我用相机拍照片的时候如果我打电话
File file = new File(getFilesDir().getAbsolutePath() + "/myImage.jpg");
Uri outputFileUri = Uri.fromFile(file);
cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
相机上的OK button
应用程序不起作用,只是什么也不做(实际上,我猜它不会保存到内部内存中,因此应用本身什么也不做)。
如果我给你打电话
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myImage.jpg");
Uri outputFileUri = Uri.fromFile(file);
cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
一切都很好,照片存储在SDCard上。
我的问题是,有没有一种方法可以在没有full-resolution的情况下将捕获的照片存储在SDCard中?
发布于 2012-11-15 16:53:15
本机摄像头应用程序不能保存图像在您的应用程序的私人内部目录,因为这些是只有您的特定应用程序可用。
相反,您可以创建一个自定义相机活动来将图像保存到您的内部目录中,或者您需要使用带有外部存储的股票相机应用程序。
注意:如果您计划创建一个自定义相机活动,请确保您的目标至少为2.3及以上。任何低于这个标准的东西都很难处理。
发布于 2012-11-15 16:52:33
照相机活动将无法将文件保存到活动的私有文件目录中,这就是为什么它悄然失败的原因。您可以将图像从外部存储移到onActivityResult中的文件dir中。
发布于 2019-07-09 06:19:08
您需要添加权限
cameraIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
这是可以使用文件提供程序的。请参考样品
public getOutputUri(@NonNull Context pContext) {
String photo = photo.jpeg;//your file name
File photoFile = new File(pContext.getFilesDir(), photo);
Uri lProviderPath = FileProvider.getUriForFile(pContext,
pContext.getApplicationContext()
.getPackageName() + ".provider", photoFile);
return lProviderPath;
}
private void capturePhoto() {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, getOutputUri(this));
cameraIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(cameraIntent, 1);
}
有关更多详细信息,请参阅下面的android文档https://developer.android.com/reference/android/support/v4/content/FileProvider
https://stackoverflow.com/questions/13402187
复制相似问题