0

I need to upgrade an APK that is distributed outside of Play Store. I was able to download the new APK and launched the install with this intent

    private void startInstall(File appApkFile) {
    if (appApkFile.exists()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            Uri apkUri = FileProvider.getUriForFile(activity, BuildConfig.APPLICATION_ID + ".provider", appApkFile);
            Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
            intent.setData(apkUri);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setDataAndType(apkUri, "application/vnd.android.package-archive");

            PackageManager packageManager = getPackageManager();
            if (intent.resolveActivity(packageManager) != null) {
                startActivity(intent);
            }
        } else {
            Uri apkUri = Uri.fromFile(appApkFile);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            PackageManager packageManager = getPackageManager();
            if (intent.resolveActivity(packageManager) != null) {
                startActivity(intent);
            }
        }
    } 
}

The install launches however because the app already exists on the device the install fails with the error message that "the package conflicts with an existing package by the same name"

Would anyone know how to pass the upgrade flag to the Install Intent action?

APK Installed Failed

Val Okafor
  • 3,371
  • 13
  • 47
  • 72

1 Answers1

1

please use signed apk file in both debug and release version

Bholendra Singh
  • 980
  • 7
  • 14