我正在開發一些Android應用程序並使用常規相機(不是自定義相機)。該應用程序具有所有必要的權限(攝像頭,寫入和讀取外部)。直到昨天一切正常:拍攝後,保存在設備庫中的圖像可以顯示在ImageView
。我升級到Android 7.0,現在相機不再保存圖像,活動結果返回null
(data.getData()
)。保存圖像不能正常工作,因爲升級到android 7
有誰知道Android 7.0中有哪些變化?
我正在開發一些Android應用程序並使用常規相機(不是自定義相機)。該應用程序具有所有必要的權限(攝像頭,寫入和讀取外部)。直到昨天一切正常:拍攝後,保存在設備庫中的圖像可以顯示在ImageView
。我升級到Android 7.0,現在相機不再保存圖像,活動結果返回null
(data.getData()
)。保存圖像不能正常工作,因爲升級到android 7
有誰知道Android 7.0中有哪些變化?
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;
}
}
,你必須給予這些許可,我希望這將有助於你.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_CONTACTS –
什麼一堆不到點代碼。沒有人要求這樣的代碼。是什麼讓你這麼想? – greenapps
文件://不允許再意圖連接或將拋出FileUriExposedException這可能會導致您的應用程序崩潰立即調用。
在你的類中使用'cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,picUri);' –
好的顯示你的代碼,我會說。 – greenapps
'現在相機不再保存圖像'。相機不保存圖像。只有相機應用程序可以這樣做。你在用嗎?您仍然可以用設備上的相機應用以正常方式拍照嗎? – greenapps