须知少年凌云志,曾许人间第一流。这篇文章主要讲述app获取自己的签名相关的知识,希望能为你提供帮助。
package com.tencent.wework.api.lcx; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Iterator; import java.util.List; import android.annotation.SuppressLint; import android.app.Activity; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.widget.Toast; public class LcxSignature {private Activity context; public LcxSignature(Activity context1) { context = context1; }/** * 遍历包名 */ public void getSign() { String paramString = context.getPackageName(); showToast("包名 = " + paramString); 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; if (packageName.equals(paramString)) { showToast("签名 = " + MD5Encode(packageinfo.signatures[0].toByteArray())); } } }/** * 根据包名获取签名 */ @SuppressLint("NewApi") public void getRawSignature() {// String paramString = "com.lc.iotstandard.ht"; String paramString = context.getPackageName(); PackageManager localPackageManager = context.getPackageManager(); PackageInfo localPackageInfo; try { localPackageInfo = localPackageManager.getPackageInfo(paramString, PackageManager.GET_SIGNATURES); if (localPackageInfo == null) { showToast("信息为 null, 包名 = " + paramString); return; } } catch (PackageManager.NameNotFoundException localNameNotFoundException) { showToast("包名没有找到..."); return; }//String result = getSignature(paramString); String result = MD5Encode(localPackageInfo.signatures[0].toByteArray()); showToast(result); ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); cm.setPrimaryClip(ClipData.newPlainText(null, result)); }/** * 根据包名获取签名 * pkg: 包名 */ public String getSignature(String pkg) { try { PackageInfo var1; var1 = context.getPackageManager().getPackageInfo(pkg, PackageManager.GET_SIGNATURES); return MD5Encode(var1.signatures[0].toByteArray()); } catch (Throwable var2) { } return ""; }private static String MD5Encode(byte[] toencode) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.reset(); md5.update(toencode); return HexEncode(md5.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }@SuppressLint("DefaultLocale") private static String HexEncode(byte[] toencode) { StringBuilder sb = new StringBuilder(toencode.length * 2); for (byte b : toencode) { sb.append(Integer.toHexString((b & 0xf0) > > > 4)); sb.append(Integer.toHexString(b & 0x0f)); } return sb.toString().toUpperCase(); }public void showToast(String info) { Toast toast = Toast.makeText(context, info, Toast.LENGTH_LONG); toast.show(); } }
【app获取自己的签名】
推荐阅读
- appium 自动化问题三--键盘关键字的使用
- Android html5和Android之间的交互
- Android 开发学习进程0.13
- appium---多线程启动app(多台设备启动app)
- Android开发 状态栏开发
- android中LayoutInflater的3种使用以及getSystemService的API
- uniapp APP下使用list组件的下拉刷新和触底加载
- Android开发 RecyclerView实现拖动与滑动ItemTouchHelper
- 当手机丢失,如何保障云盘APP中的数据安全()