javaandroid-intentinstallationapkandroid-fileprovider

Why don't apks auto-install on Samsung devices


I've come across a problem with my own third-party app store. When users download an item from our app it downloads then tries to install automatically using

File toInstall = new File(mFilePath);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Uri contentUri = FileProvider.getUriForFile(context, "package_name.fileprovider", toInstall);
        Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
        intent.setData(contentUri);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        context.startActivity(intent);
    } else {
        Uri apkUri = Uri.fromFile(toInstall);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

}

All works great on most devices, apart from mainly Samsung devices: the file downloads but does not install. Why?

Edit 1

My file provider xml:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path path="Android/data/package_name/" name="files_root" />
<external-path path="." name="external_storage_root" />
</paths>

Edit 2

Do I need any permissions in my manifest such as INSTALL_PACKAGE, or perhaps a runtime permission?

I just find it strange that it's only Samsung-based devices.


Solution

  • think the answer was simpler than i thought. alls i had to was add a line in my manifest stating this permission

     <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
    

    its a new security measure that came out in Oreo i believe