当我在windows中使用此命令时keytool -exportcert -alias androiddebugkey -keystore%HOMEPATH%.android \ debug.keystore | openssl sha1 -binary | openssl base64获取android hash这条消息出现'keytool'不被识别为内部或外部命令, 可操作程序或批处理文件。
答案 0 :(得分:0)
public void generateFBKeyHash(Context mContext) {
try {
PackageInfo info = mContext.getPackageManager().getPackageInfo(
"YOUR PACKAGE NAME IN YOUR MANIFEST",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.e("fb key hash", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
Log.e("failed", e.getMessage());
}
}
注意:确保您的清单中包含元数据
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />