日志如下
W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
W/System.err: at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:605)
W/System.err: at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:579)
W/System.err: at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417)
原因
AndroidManifest.xml中FileProvider配置的authorities与代码中的不同
//Manifest
<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/file_path"/>
</provider>
//java
String authority = activity.getPackageName() + ".fileProvider";
uri = FileProvider.getUriForFile(activity, authority, takePictureFile);
找了好久 ${applicationId}.fileprovider
和.fileProvider
P一个小写一个大写,改成一致就行
网友评论