Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to be notified when APK fails to being installed?

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: enter image description here

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!

like image 841
dor506 Avatar asked Dec 01 '11 09:12

dor506


1 Answers

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;
}
like image 104
javiersigler Avatar answered Sep 22 '22 20:09

javiersigler