0
嗨,首先我知道這個問題已經被問了,但我堅持了一天多,我想用相機意圖拍照並保存在手機的ExternalStoragePublicDirectory
,但在服用後圖片不會返回到OnActivityResult
,也不會保存圖片。它不工作在Android 6和7: 任何幫助將被諷刺!相機不返回到OnActivityResult
Uri imageUri = setImageUri();
Intent intent1 = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent1.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
intent1.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
List<ResolveInfo> resInfoList =
MedicalActivity.this.getPackageManager().queryIntentActivities(intent1,
PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName =resolveInfo.activityInfo.packageName;
MainActivity.this.grantUriPermission(packageName, imageUri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
startActivityForResult(intent1, CAPTURE_IMAGE);
集圖像烏里:
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT) {
File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"myappimages");
if (!mediaStorageDir.exists()) {mediaStorageDir.mkdir();}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File file;
file = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
Uri imgUri = FileProvider.getUriForFile(MedicalActivity.this,
BuildConfig.APPLICATION_ID + ".provider",
file);
return imgUri;
}
文件提供路徑:
<external-path name="myapp_images_path" path="Pictures/myappimages"/>
是的,我加 那個也是。我請求'Manifest.permission.CAMERA'和'Manifest.permission.WRITE_EXTERNAL_STORAGE',並從'onRequestPermissionsResult'啓動攝像機意圖,但我仍然有同樣的問題! – saeed