0

I want to upgrade my app. and i get new version .apk on server. It is work on manually if delete old version app. on device but if I do not delete old version app. does not work again I take same parse error.

I added AndroidManifest file:
<uses-permission android:name="android.permission.INSTALL_PACKAGES" tools:ignore="ProtectedPermissions" />

I test another .apk and it is work.

public class VersionUpdateTask extends AsyncTask<String, Float, String> {

@Override
protected void onPostExecute(String result) {
    mWakeLock.release();

    updateManager.updateBar.stop();

    else {

        try {

            String PATH = Environment.getExternalStorageDirectory() + "/download/";
            File file = new File(PATH, updateManager.apkOutPath);
            if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.N) {
                Uri fileUri = FileProvider.getUriForFile(updateManager.updateContext,updateManager.updateContext.getPackageName() + ".provider", file);
                Intent intent = new Intent(Intent.ACTION_VIEW, fileUri);
                intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
                intent.setDataAndType(fileUri, "application/vnd.android" + ".package-archive");
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                updateManager.updateContext.startActivity(intent);

            } else {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


                updateManager.updateContext.startActivity(intent);
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }

    }



}

}
  • That's because the apk file is broken. Did the old version and new version have the same name? – zhh Jan 16 '18 at 11:24
  • Yes, they are same but i tried to install downloaded new apk. version it works when delete old version app. –  Jan 16 '18 at 11:26
  • There is a possible reason: Assume the size of your old version is 4.1MB and the size of your new version is 4.0MB. And assume the file name is "app.apk". After you have downloaded your new version, the "app.apk" is still 4.1MB but the first 4.0MB is your new version so this is a broken apk file. – zhh Jan 16 '18 at 11:29
  • Check if your old version is larger than your new version. – zhh Jan 16 '18 at 11:30
  • I check old versions smaller than new version. –  Jan 16 '18 at 11:42
  • Check if your new version on your phone is the same apk on your server. And check if the new version on your server is the same with your original new version. There must be a broken file during transmission. – zhh Jan 16 '18 at 11:48
  • I don't think because i said i try downloaded new .apk manually is work.But it try them thanx. –  Jan 16 '18 at 12:00

0 Answers0