Skip to content

Commit 4f8fa0e

Browse files
committed
see 10/12 log
1 parent 860bf2a commit 4f8fa0e

26 files changed

+1065
-527
lines changed

utilcode/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 11
99
targetSdkVersion 23
10-
versionCode 8
11-
versionName "1.2.1"
10+
versionCode 9
11+
versionName "1.2.2"
1212
}
1313
buildTypes {
1414
release {

utilcode/src/main/java/com/blankj/utilcode/utils/ActivityUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.blankj.utilcode.utils;
22

3+
import android.app.ActivityManager;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.os.Bundle;
67

8+
import java.util.List;
9+
710
/**
811
* <pre>
912
* author: Blankj

utilcode/src/main/java/com/blankj/utilcode/utils/AppUtils.java

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.io.InputStreamReader;
1818
import java.io.OutputStream;
1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.List;
2122

2223
/**
@@ -32,36 +33,6 @@ public class AppUtils {
3233
private AppUtils() {
3334
throw new UnsupportedOperationException("u can't instantiate me...");
3435
}
35-
36-
37-
/**
38-
* 获取应用的 SHA1 值, 可据此判断高德,百度地图 key 是否正确
39-
* @param context 上下文
40-
* @return 应用的 SHA1 字符串, 比如: 53:FD:54:DC:19:0F:11:AC:B5:22:9E:F1:1A:68:88:1B:8B:E8:54:42
41-
*/
42-
public static String getSHA1(Context context) {
43-
try {
44-
PackageInfo info = context.getPackageManager().getPackageInfo(
45-
context.getPackageName(), PackageManager.GET_SIGNATURES);
46-
byte[] cert = info.signatures[0].toByteArray();
47-
MessageDigest md = MessageDigest.getInstance("SHA1");
48-
byte[] publicKey = md.digest(cert);
49-
StringBuilder hexString = new StringBuilder();
50-
for (byte aPublicKey : publicKey) {
51-
String appendString = Integer.toHexString(0xFF & aPublicKey).toUpperCase();
52-
if (appendString.length() == 1)
53-
hexString.append("0");
54-
hexString.append(appendString);
55-
hexString.append(":");
56-
}
57-
String result = hexString.toString();
58-
return result.substring(0, result.length() - 1);
59-
} catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
60-
e.printStackTrace();
61-
}
62-
return "";
63-
}
64-
6536

6637
/**
6738
* 判断App是否安装
@@ -400,6 +371,31 @@ public static Signature[] getAppSignature(Context context, String packageName) {
400371
}
401372
}
402373

374+
/**
375+
* 获取应用签名的的SHA1值
376+
* <p>可据此判断高德,百度地图key是否正确</p>
377+
*
378+
* @param context 上下文
379+
* @return 应用签名的SHA1字符串, 比如:53:FD:54:DC:19:0F:11:AC:B5:22:9E:F1:1A:68:88:1B:8B:E8:54:42
380+
*/
381+
public static String getAppSignatureSHA1(Context context) {
382+
return getAppSignatureSHA1(context, context.getPackageName());
383+
}
384+
385+
/**
386+
* 获取应用签名的的SHA1值
387+
* <p>可据此判断高德,百度地图key是否正确</p>
388+
*
389+
* @param context 上下文
390+
* @return 应用签名的SHA1字符串, 比如:53:FD:54:DC:19:0F:11:AC:B5:22:9E:F1:1A:68:88:1B:8B:E8:54:42
391+
*/
392+
public static String getAppSignatureSHA1(Context context, String packageName) {
393+
Signature[] signature = getAppSignature(context, packageName);
394+
if (signature == null) return null;
395+
return EncryptUtils.encryptSHA1ToString(signature[0].toByteArray()).
396+
replaceAll("(?<=[0-9A-F]{2})[0-9A-F]{2}", ":$0");
397+
}
398+
403399
/**
404400
* 判断App是否是系统应用
405401
*

0 commit comments

Comments
 (0)