Problem - Intent to install APK file - Android Nougat

Asked

Viewed 717 times

0

I searched extensively and did not find the problem. While trying to install a file APK using a Intent in the Android Nougat, simply does not install and displays the following warning: "A problem occurred while parsing the package".

Works perfectly to open PDF files, for example, with settings to open this type of file (.PDF). But to install files .APK doesn’t work.

In the LogCat it does not present any error e with this I cannot arrive at any solution.

What could be wrong?

Follows code:

Manifest:

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="br.com.xxxxxxx.xxxxxxx.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/filepaths"/>
</provider>

xml/filepaths:

<files-path name="storage/emulated/0" path="."/>

Code:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    try {
        Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
        File file = new File(getContext().getFilesDir(), "app-debug.apk");
        Uri uri = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".fileprovider", file);

        intent.setDataAndType(uri, "application/vnd.android.package-archive");
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(intent);
        finish();
    } catch (Exception e) {
        e.printStackTrace();
    }
}else{
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        File file = new File(Environment.getExternalStorageDirectory() + "/app-debug.apk");

        intent.setAction(android.content.Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(intent);
        finish();
    } catch (Exception e) {
        e.getMessage();
    }
}

Please, what could be wrong with this code? Can anyone help me?

  • It seems that the minSdkVersion is not compatible with the cell phone

  • Thanks for the feedback, but could you be a little more specific? How can I fix this?

  • When you build an app, you tell us the minimum API you need to run it. For example, android 5.0 runs API 21. If you create an app with the information in minSdkVersion = 22 and try to install it on a device whose Android version is 5.0 you may receive this error: "There was a problem analyzing the package", that is, analyzed the package to be installed and concludes that it is incompatible.

  • Ola Reginaldo. I’m compiling on API 25, on Android Nougat. As I mentioned, in the same application I use an Intent to open PDF files, using Fileprovider, directed to devices with API 24 or higher and works normally. The issue is to run the file with extension APK.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.