خرید بک لینک

Vote count: 0

I'm trying to give the user the option to either supply a photo they've taken in the past, or take a new photo right now. The issue is that when I try to use the image, I get a "permission denied."

This is where I make the chooser intent:

final File root = new File(Environment.getExtealStorageDirectory() + File.separator + "MyDir" + File.separator);
root.mkdirs();
final String fname = "img_" + System.currentTimeMillis() + ".jpg";
outputFileUri = Uri.fromFile(new File(root, fname));

Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE_SECURE);
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
Intent pickPhotoIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickPhotoIntent.setType("image/*");

Intent chooserIntent = Intent.createChooser(pickPhotoIntent, "Take a photo or select one from your device");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {takePhotoIntent});

startActivityForResult(chooserIntent, 1);

outputFileUri is a field variable in the class. I use that to load an image as so:

 String url = selectedImageUri.toString();
 final Bitmap image = Picasso.with(context).load(url).get();

And I get an error as follows:

java.io.FileNotFoundException: /storage/emulated/0/MyDir/img_1466710420779.jpg: open failed: EACCES (Permission denied)

This used to work when I had it in an Activity class, but I converted that to a Fragment class and it stopped working (I changed nothing else - all I did was make it a fragment).

Anyone have ideas on how to fix this?

asked 36 secs ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 4 تير 1395 ساعت: 3:04

صفحه بندی