Hi first of all i know this question already has been asked but i am stuck on it more than one day i want to take a picture with camera intent and save it on ExternalStoragePublicDirectory
of phone but after taking the picture it doesn't return to OnActivityResult
nor the picture is saved. it's not working in android 6 and 7:
any help would be appericiated!!
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);
set image Uri:
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;
}
File provider path:
<external-path name="myapp_images_path" path="Pictures/myappimages"/>