My situation is that I have a pre-installed apk that uses the wrong key store. Therefore, direct installation will result in a failure due to an inconsistent signature. I need to check the signature first to make sure it can be installed smoothly.
Here is my solution .
As this code says, you can get the signature from the installed apk.
Details:
Signature sig = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures[0];
Second: compare hashCode releaseApk. In my case, I downloaded this apk from my server and put it in sd_card.
Signature releaseSig = context.getPackageManager().getPackageArchiveInfo("/mnt/sdcard/myReleaseApk.apk", PackageManager.GET_SIGNATURES).signatures[0];
Lastly, compare hashCode.
return sig.hashCode() == releaseSig.hashCode;
I tried the code above, it works fine. If hashCode is different, you just need to remove the old apk, or if this system application and device is embedded, you can simply use runtime to remove it , and then install a new apk signature.
Shengfeng Li Jul 27 '16 at 15:18 2016-07-27 15:18
source share