0

I am trying to update my current unsigned app with new version unsigned app but it always is giving error like "App Not Installed".

Is there any reference which say unsigned apk can not be installed.
Here is my code :

try {

        File file = FileUtils.getExternalStorageFile("apk_folder", Constants.APK_FILE_NAME);

        if (file.exists()) {
            Uri packageURI = Uri.parse(pInfo.packageName);
            Intent intent = new Intent(Intent.ACTION_VIEW, packageURI);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Uri apkURI = FileProvider.getUriForFile(getApplicationContext(), getPackageName() + ".provider", file);
                intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } else {
                intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
            }

            startActivity(intent);

            //Set APK updated.
            LMPSharedPrefs.getInstance().write(SharedPrefsConstants.KEY_APK_UPDATED, Constants.APK_UPDATED);

            //Delete APK from file.
            FileUtils.deleteFileFromExternalStorage("apk_folder", Constants.APK_FILE_NAME);
        } else{
            Log.d("APK", "APK file is not present" );
        }

    } catch (Exception e) {
        Log.d("Exception", "Exception while updating the APK" + e.getLocalizedMessage());
    }

Here is my provider_path.xml :

<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path name="filePath" path="." />
<external-path name="external_files" path="/apk_folder/"/>
</paths> 

Let me know if i am doing anything wrong.

Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160

0 Answers0