0

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"/>
saeed
  • 21
  • 4

1 Answers1

0

from android version greater than 6 and equal to 6 you need to request for permission of storage and camera for example check this link https://androidkennel.org/android-camera-access-tutorial/ and https://developer.android.com/guide/topics/permissions/requesting.html

karthik
  • 347
  • 1
  • 9
  • Yes i add that too. i request for 'Manifest.permission.CAMERA' and 'Manifest.permission.WRITE_EXTERNAL_STORAGE' and start camera intent from 'onRequestPermissionsResult' but i still have the same issue! – saeed Jul 11 '17 at 08:38