Я пытаюсь использовать FileProvider
, но не удается проанализировать XML и выдает эту ошибку:
java.lang.NullPointerException: Попытка вызвать виртуальный метод 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData (android.content.pm.PackageManager, java.lang.String) 'для ссылки на пустой объект
Это код вызова:
Log.i(TAG, "Completed download of update file");
statusMessage = "Completed download of update file";
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (context != null) {
Log.i(TAG, "Context is: " + context.toString());
} else {
Log.w(TAG, "Context is null");
}
if (context.getString(R.string.file_provider_authority) != null) {
Log.i(TAG, "Authority is: " + context.getString(R.string.file_provider_authority));
} else {
Log.w(TAG, "Authority is null");
}
if (outputFile != null) {
Log.i(TAG, "outputFile is: " + outputFile.toString());
} else {
Log.w(TAG, "outputFile is null");
}
uri = FileProvider.getUriForFile(context, context.getString(R.string.file_provider_authority), outputFile);
statusMessage = "uri set";
} else {
uri = Uri.fromFile(outputFile);
}
Log.i(TAG, "URI successfully set");
statusMessage = "URI successfully set";
Ни один из параметров не является null
, и "URI успешно установлен" никогда не регистрируется.Поэтому мне кажется, что проблема заключается в файлах XML.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="uk.co.letsdelight.letsdelight">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.REQUEST_WRITE_PERMISSION" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="@drawable/icon_trans"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="@strings/file_provider_authority"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity android:name=".AboutActivity" />
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="uk.co.letsdelight.letsdelight.MainActivity" />
</activity>
</application>
</manifest>
file_provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="cache" path="." />
</paths>
Любые идеи о том, что я могупопробуйте решить эту проблему, пожалуйста?