检索APK签名在运行时为AndroidAPK、Android

2023-09-05 00:29:32 作者:流氓绅士 i

有没有一些方法来检索有关的apk签名在运行时的信息?

Is there some way to retrieve information about the apk signature at runtime?

例如我有同样的应用程序有2个不同的签名签:APP-1.apk和app-2.apk,我希望能够区分这两种APK在运行时的。那可能吗?

For example I have the same App signed with 2 different signatures: app-1.apk and app-2.apk and I'd like to be able of differentiate both apk in run time. Is that possible?

我的目标是使用一个外部服务器,并根据应用程序和签名的版本code实行许可制度。

My goal is to implement a licensing system using a external server and based on the version code of the application and the signature.

推荐答案

您可以使用PackageManager访问的apk签名。  在包管理器中定义PackageInfo标志返回有关包中包含的签名信息。

You can access apk signature using PackageManager. PackageInfo flag defined in Package Manager return information about the signatures included in the package.

Signature[] sigs = context.getPackageManager().getPackageInfo(context.getPackageName(),PackageManager.GET_SIGNATURES).signatures;    
for (Signature sig : sigs)
{
    Log.i("App", "Signature : " + sig.hashCode());
}

http://developer.android.com/reference/android/内容/ PM / PackageManager.html