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();
}
}
}
}