Android获取apk程序签名信息代码示例

时间:2022-09-20 13:32:24

复制代码 代码如下:


这是获取apk包的签名信息
private String getSign(Context context) {
  PackageManager pm = context.getPackageManager();
  List<PackageInfo> apps = pm.getInstalledPackages(PackageManager.GET_SIGNATURES);
  Iterator<PackageInfo> iter = apps.iterator();
  while(iter.hasNext()) {
       PackageInfo packageinfo = iter.next();
       String packageName = packageinfo.packageName;

       return packageinfo.signatures[0].toCharsString();
       if (packageName.equals(instance.getPackageName())) {
          MediaApplication.logD(DownloadApk.class, packageinfo.signatures[0].toCharsString());
          return packageinfo.signatures[0].toCharsString();
       }
}
  return null;
}

返回的签名信息结果为很长的一串数据