0

Let say that I have different certificates A-certificate and B-certificate, and I sign 3 apps (one with A , and two with B)

How can I check form application signed with certificate B that the other app is also signed with B (not with A)

I need some method that will programmatically check if some app is signed with the same certificate as some other app

the method stub should look like this

public boolean sameCertificate(String packagename1,String packagename2){
//some comparison
//return true/false
}
Lukap
  • 31,523
  • 64
  • 157
  • 244

2 Answers2

1
public boolean sameCertificate(Context context, String packageName1, String packageName2) {
    return context.getPackageManager().checkSignatures(packageName1, packageName2) == PackageManager
            .SIGNATURE_MATCH;
}
David Vávra
  • 18,446
  • 7
  • 48
  • 56
-2

The easiest way is to not even need to check yourself -- just give both of those apps the same shared user id in your manifests; that way Android will enforce that they must be signed alike.

If you prefer the manual approach, you can get an application's signature using the PackageManager. How to get APK signing signature? shows you more details.

Community
  • 1
  • 1
mah
  • 39,056
  • 9
  • 76
  • 93