Flutter android应用程序,我想下载并写入文件,但出现此错误:
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
为解决上述错误,我添加了提供程序和xmlfile及其依赖项,但现在我收到未找到“ android.support.v4.content.FileProvider”的错误
<application>
<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>
</application
implementation 'com.android.support:support-v4:28.0.0'
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.android.support:design:28.0.0"
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation "com.android.support:support-core-utils:28.0.0"
答案 0 :(得分:1)
是的,我解决了
我想写文件,这就是为什么我在清单中添加<provider></provider>
的原因。但是我写文件的方式很简单,所以我从那里删除了<provider>
标记
然后我使用:
写入文件final response2 = await http.get(url);
var bytes = response2.bodyBytes;
var dirc = Directory("/storage/emulated/0/MyFiles");
if(dirc.exists()!=true){
dirc.create();
}
File file = new File('${dirc.path}/$filename');
var newFile = await file.writeAsBytes(bytes);
await newFile.create();
if(newFile.exists() != null) {
print("file create successfully");
// showNotification
}
在写入文件之前,您应该先请求存储权限