> 文档中心 > 调启Apk安装失败 Couldn‘t find meta-data for provider with authority

调启Apk安装失败 Couldn‘t find meta-data for provider with authority

上网找了几小时的文章一个一个的试结果全没用,还是报错,我这调试的设备是Android11,下面是我解决了的代码

    public static  void installApk(Context context,String downloadApk) { Intent intent = new Intent(Intent.ACTION_VIEW); File file = new File(downloadApk); //L.i("安装路径=="+downloadApk); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {     Uri apkUri = FileProvider.getUriForFile(Objects.requireNonNull(context), BuildConfig.APPLICATION_ID + ".fileProvider", file);//这句很重要     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);     intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);     intent.setDataAndType(apkUri, "application/vnd.android.package-archive"); } else {     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);     Uri uri = Uri.fromFile(file);     intent.setDataAndType(uri, "application/vnd.android.package-archive"); } context.startActivity(intent);    }

file_paths里的代码

<external-path path="." name="external_storage_root" />

AndroidMainfest里的代码

 <provider     android:name="androidx.core.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_paths" /> </provider>

还有就是要注意authorities属性的大小写,必须一致