-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
Hi all
It's please add codes below, to fix problem on android N
Also @Tofira thanks for this library.
- Add code to
AndroidManifest.xml
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
- Create file
provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external_files"
path="." />
</paths>
- Update file
CameraPickerManager.java
protected void sendToExternalApp() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mProcessingPhotoUri = getImageFileCompat();
intent.putExtra(MediaStore.EXTRA_OUTPUT, mProcessingPhotoUri);
activity.startActivityForResult(intent, REQUEST_CODE_SELECT_IMAGE);
}
private Uri getImageFileCompat() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en
String imageName = activity.getString(R.string.app_name);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
String imageFileName = imageName + timeStamp + "_";
File storageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM), "Camera");
try {
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
return FileProvider.getUriForFile(activity,
BuildConfig.APPLICATION_ID + ".provider",
image);
} catch (IOException e) {
e.printStackTrace();
}
return null;
} else {
return getImageFile();
}
}
Metadata
Metadata
Assignees
Labels
No labels