I am having trouble using the crop intent in Android.
I am storing images in the internal storage allocation for my app and I want to be able to crop them and then set them as the wallpaper.
I can get it to work with an image stored in external storage and using this code:
cropIntent.setDataAndType(Uri.fromFile(new File(uri)), "image/*");
When I execute the code below the intent fails to launch the crop intent and a 0 result code is returned.
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(FileProvider.getUriForFile(activity, "com.example.test.fileprovider", new File(uri)), "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 9);
cropIntent.putExtra("aspectY", 16);
cropIntent.putExtra("return-data", true);
cropIntent.putExtra("scale", true);
activity.startActivityForResult(cropIntent, PIC_CROP);
From Storage Options | Android Developers:
ACTION_CROP
launches an "other application" that supports cropping, and passes it the URI of the file to crop. If that file is in internal storage, it is not directly accessible to the cropping application.Using a
FileProvider
to provide an internal file to other apps requires some configuration. From Setting Up File Sharing | Android Developers:The following
FileProvider
sample integrates your code and successfully opens the crop activity on an image in internal storage (tested on a Nexus 5, stock Android 5.1.1):AndroidManifest.xml
res/xml/filepaths.xml
MainActivity.java