将图像保存到gallery自升级到android 7后不起作用
我正在开发一些Android应用程序,并使用普通摄像头(不是定制的)。该应用程序具有所有必要的权限(摄像头、外部写入和读取)。直到昨天,一切正常:拍摄后,图像保存在设备库中,可以显示在将图像保存到gallery自升级到android 7后不起作用,android,image,android-gallery,android-7.0-nougat,Android,Image,Android Gallery,Android 7.0 Nougat,我正在开发一些Android应用程序,并使用普通摄像头(不是定制的)。该应用程序具有所有必要的权限(摄像头、外部写入和读取)。直到昨天,一切正常:拍摄后,图像保存在设备库中,可以显示在ImageView中。我升级到Android 7.0,现在相机不再保存图像,活动结果返回null(data.getData()) 有人知道Android 7.0中发生了什么变化吗?公共类SaveImageAsync扩展了AsyncTask{ public class SaveImageAsync extends A
ImageView
中。我升级到Android 7.0,现在相机不再保存图像,活动结果返回null
(data.getData()
)
有人知道Android 7.0中发生了什么变化吗?公共类SaveImageAsync扩展了AsyncTask{
public class SaveImageAsync extends AsyncTask<Integer, Void, Void> {
@Override
protected Void doInBackground(Integer... params) {
try {
InputStream in;
BufferedInputStream buf;
int position = params[0];
if (URLUtil.isNetworkUrl(use image here)) {
in = new URL(use image here
).openStream();
buf = new BufferedInputStream(in);
Bitmap _bitmapPreScale = BitmapFactory.decodeStream(buf);
int oldWidth = _bitmapPreScale.getWidth();
int oldHeight = _bitmapPreScale.getHeight();
int newWidth = 2592;
int newHeight = 1936;
float scaleWidth = ((float) newWidth) / oldWidth;
float scaleHeight = ((float) newHeight) / oldHeight;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap _bitmapScaled = Bitmap.createBitmap(_bitmapPreScale, 0, 0, oldWidth, oldHeight, matrix, true);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
_bitmapScaled.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),"wave");
directory.mkdirs();
directory.mkdir();
File f = new File(directory, "writeurnamefolder_Gallery" + System.currentTimeMillis() + ".jpg");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
} else if (URLUtil.isFileUrl(use here original image)) {
MediaStore.Images.Media.insertImage(getContentResolver(), Uri.parse(get your image here.getPath(), "writeurnamefolder_Gallery" + System.currentTimeMillis(), "Gallery Image :");
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
@凌驾
受保护的Void doInBackground(整数…参数){
试一试{
输入流输入;
缓冲输入流buf;
int位置=参数[0];
if(URLUtil.isNetworkUrl(在此处使用图像)){
in=新URL(在此处使用图像
).openStream();
buf=新的BufferedInputStream(in);
位图_bitmapPreScale=BitmapFactory.decodeStream(buf);
int oldWidth=_bitmapPreScale.getWidth();
int oldHeight=_bitmapPreScale.getHeight();
int newWidth=2592;
int newHeight=1936;
float scaleWidth=((float)newWidth)/oldWidth;
浮动比例高度=((浮动)新高度)/旧高度;
矩阵=新矩阵();
矩阵。后标度(标度宽度、标度高度);
位图_bitmapScaled=Bitmap.createBitmap(_bitmapPreScale,0,0,oldWidth,oldHeight,matrix,true);
ByteArrayOutputStream字节=新建ByteArrayOutputStream();
_bitmapScaled.compress(位图.CompressFormat.JPEG,40,字节);
File directory=新文件(Environment.getExternalStoragePublicDirectory(Environment.directory_DCIM),“wave”);
mkdirs()目录;
mkdir()目录;
文件f=新文件(目录“writeurnamefolder_Gallery”+System.currentTimeMillis()+“.jpg”);
f、 createNewFile();
FileOutputStream fo=新的FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
}else if(URLUtil.isFileUrl(在此处使用原始图像)){
MediaStore.Images.Media.insertImage(getContentResolver(),Uri.parse(在这里获取图像.getPath(),“writeurnamefolder_Gallery”+System.currentTimeMillis(),“Gallery图像:”);
}
}捕获(IOE异常){
e、 printStackTrace();
}
返回null;
}
}
文件://不允许再附加意图,否则会引发FileUriExposedException,这可能会导致您的应用程序立即调用崩溃。您必须授予这些权限,我希望这将对您有所帮助。写入\u外部\u存储},我的\u权限\u请求\u读取\u联系人,其中包含大量不符合要点的代码。没有人你为什么这么想?在你的类中使用这个cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,picUri)
我想说的是,展示你的代码。现在相机不再保存图像了
。相机不保存图像。只有相机应用程序可以保存图像。你正在使用相机应用程序吗?你仍然可以用相机应用程序在你的设备上正常拍照吗?保存在设备库中的图像
。不。图像保存在设备存储库中e、 无法将图像保存到gallery,因为gallery应用程序不是存储空间,而只是显示设备上图片的应用程序。