【发布时间】:2017-08-18 16:25:53
【问题描述】:
如何将相机拍摄的图像保存到图库中?我有这个代码,但不保存图像
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
几乎都用这个
private void galleryAddPic() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
但没有积极的结果,在我的清单中我使用了这个权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>
【问题讨论】:
-
你添加运行时权限了吗
-
出现的唯一权限是如果我想授予使用相机的权限
-
您在哪个操作系统版本中运行您的应用程序
-
在 6.0 和 7.1 中
-
那么您需要询问运行时权限才能将图像存储在内部存储中我的朋友read from docs about runtime permsiion
标签: android