All I am trying to do is take a picture with the Camera, save it and display it in an ImageView.
I followed the android tutorial above and keep getting an error (a NullPointerException) on the line:
Uri photoURI = FileProvider.getUriForFile(this, "com.example.android.fileprovider", photoFile);
I finally got it to work!
Remember to put the provider tag INSIDE the application tag in the manifest file - that was my mistake (my provider tag was OUTSIDE of the application tag), and the reason you get this error, which basically says it cannot find the defintion of the Provider.
Also make sure you have the correct paths in the .xml file. Here is my version
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-path name="my_images" path="Android/data/org.projects.cameraapp/files/Pictures" /> </paths>
Of course you have to change the path - my package name is org.projects.camerapp
My actual Provider then looks like this:
<provider android:name="android.support.v4.content.FileProvider" android:authorities="org.projects.cameraapp.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths"> </meta-data> </provider>
Of course - again you need to change the package name. You can see all the source at the GitHub repository.