Introduction
The camera intent android nougat support tutorial describes the changes required for how to support file Uri’s to android nougat and later.
For android nougat (SDK 24) and later a file Uri can no longer be passed to another android application via the android intent. Instead a Content:Uris with storage permissions applied must be passed instead.
This android development tutorial will describe the steps required for creating files and folders with the correct permissions which can then be passed to another application via the android intent.
Get Code
The code is now on github you can get it from here
https://github.com/mobapptuts/camera_intent.git Tag camera-intent-nougat
or else run this command
git clone https://github.com/mobapptuts/camera_intent.git –branch camera-intent-nougat
This video describes how to import the code from github using android studio and also how to use git tags
Steps
Setting up the FileProvider
Add the provider to the manifest file
Make sure to include it inside the application tag
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true" > <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths" /> </provider>
Create an resource xml folder and then add a filepaths.xml file to that file
<paths> <external-path path="." name="mediaimages" /> </paths>
Use the FileProvider to get the Uri from the file
String authorities = getApplicationContext().getPackageName() + ".fileprovider"; Uri imageUri = FileProvider.getUriForFile(this, authorities, photoFile); callCameraApplicationIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); // callCameraApplicationIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
Camera intent android nougat support summary
In this android developers tutorial we learned to steps involved with sharing files to other applications. This is now required for Android versions of 7.0 (nougat) or later.
The FileProvider needs to be added to the android manifest file. An xml file is required for specifying the locations of the files to be shared.
The FileProvider must then be used to get the Uri from the file which can then be shared with another application.