Android 获取应用签名
生活随笔
收集整理的這篇文章主要介紹了
Android 获取应用签名
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、根據代碼獲取應用簽名
應用簽名工具類:ApplySigningUtils.java
public class ApplySigningUtils {/*** 獲取應用簽名** @param context* @param packageName* @return*/public static String getRawSignatureStr(Context context, String packageName) {try {Signature[] signs = getRawSignature(context, packageName);String signValidString = getSignValidString(signs[0].toByteArray());return signValidString;} catch (Exception e) {e.printStackTrace();}return null;}public static Signature[] getRawSignature(Context context, String packageName) {if (packageName == null || packageName.length() == 0) {return null;}try {PackageInfo info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);if (info != null) {return info.signatures;}} catch (PackageManager.NameNotFoundException e) {e.printStackTrace();}return null;}private static String getSignValidString(byte[] paramArrayOfByte) throws NoSuchAlgorithmException {MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");localMessageDigest.update(paramArrayOfByte);return toHexString(localMessageDigest.digest());}private static String toHexString(byte[] paramArrayOfByte) {if (paramArrayOfByte == null) {return null;}StringBuilder localStringBuilder = new StringBuilder(2 * paramArrayOfByte.length);for (int i = 0; ; i++) {if (i >= paramArrayOfByte.length) {return localStringBuilder.toString();}String str = Integer.toString(0xFF & paramArrayOfByte[i], 16);if (str.length() == 1) {str = "0" + str;}localStringBuilder.append(str);}} }在MainActivity的onCreate調用簽名工具類(記得安裝已打包的APK,直接運行獲取到的簽名是不正確的)
public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);String s = ApplySigningUtils.getRawSignatureStr(this,getPackageName());Log.d("應用簽名:",""+ s);} }? 這樣就能獲取到應用簽名啦
2、可從微信開發平臺下載工具進行獲取
安裝完APK,輸入自己的應用包名,就可以獲取應用簽名
APK下載地址如下:
https://res.wx.qq.com/open/zh_CN/htmledition/res/dev/download/sdk/Gen_Signature_Android2.apk??????
總結
以上是生活随笔為你收集整理的Android 获取应用签名的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PCI Geomatica 操作视频专辑
- 下一篇: cisco 2811路由器详细配置