0

This code open an app that i made, so in the condition of api 24 doesnt work or star the app, so the result its an error.

                File file = new File(uri);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    Uri apkUri = FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", file);
                    Intent intentOne = new Intent(Intent.ACTION_INSTALL_PACKAGE);
                    intent.setData(apkUri);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    activity.startActivity(intentOne);
                } else {
                    Intent install = new Intent(Intent.ACTION_VIEW);
                    install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    install.setDataAndType(Uri.parse(uri), "application/vnd.android.package-archive");
                    activity.startActivity(install);
                }

This cause the next error:

Caused by: 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
        at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:605)
        at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:579)
        at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:417)
        at com.sysvoid.service.Receiver.onReceive(Receiver.java:52)
        at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_55615(LoadedApk.java:1400)
        at android.app
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Tamir Abutbul Jul 07 '19 at 15:51
  • `BuildConfig.APPLICATION_ID + ".provider"` does not match the `android:authorities` attribute in your `` in the manifest, or you do not have a `` for your `FileProvider`. See [the `FileProvider` documentation](https://developer.android.com/reference/androidx/core/content/FileProvider). – CommonsWare Jul 07 '19 at 15:55

0 Answers0