Uri.parse(pictureImagePath)是 /storage/emulated/0/Pictures/20171125_131914.jpg
但它返回null。 我错过了什么? 请帮忙!!!
以下是调用相机:
if(Build.VERSION.SDK_INT>=24){
try{
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
}catch(Exception e){
e.printStackTrace();
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = timeStamp + ".jpg";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
pictureImagePath = storageDir.getAbsolutePath() + "/" + imageFileName;
File file = new File(pictureImagePath);
Uri outputFileUri = Uri.fromFile(file);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, REQUEST_CAMERA);
以下是代码
File imgFile = new File(pictureImagePath);
if (imgFile.exists()){
bitmapImage = null;
bitmapImage = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
RequestBody requestFile = RequestBody.create(MediaType.parse(getContentResolver().getType(Uri.fromFile(imgFile))), imgFile);