Im writing an application. In the application i download programatically an APK and start an intent which launches the APK installtion.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")),
"application/vnd.android.package-archive");
startActivity(intent);
it all works well.
but when i try, for example, to launch an installation of a coruupted APK There's a dialog which comes up:
I want to be notified when there's a problem installing the APK (corrupted APK, not enough space, etc...).
So , is there a way (Event or something) to be notified about that, so I can replace the "Parse error" defalt dialog with my own dialog?
thanks!
I am not 100% sure if this method will work in all the potential situations but I have been testing and at least works for me.
I have not found information about detecting installation errors in Android so I try to preemptively detect if the apk file is corrupted.
According to this link, apks are simply jarfiles with dalvik codes. So you can use a zip decompression to detect the file have been corrupted and any problem parsing the package.
boolean corruptedApkFile = false;
try {
new JarFile(updateFileFullPath); //Detect if the file have been corrupted
} catch (Exception ex) {
corruptedApkFile = true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With