keytool -exportcert -alias yoursAlisa -keystore Yours.jks | openssl sha1 -binary | openssl base64
在Android Studio的Terminal里输入上述命令: 其中yoursAlisa为你的签名alias; Yours.jks为你的签名。
生成一个28位的字符串就是了。
或者在Activity的onCreate里执行这段代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.lijingnan.samples.hello",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
...
网友评论