Obtaining the SHA-1 fingerprint of your certificate keystore file
suggest changeIn order to obtain a Google Maps API key for your certificate, you must provide the API console with the SHA-1 fingerprint of your debug/release keystore.
You can print that fingerprint with the JDK's keytool program, as described here in the docs.
Another approach is to obtain the fingerprint programmatically by running this snippet with your app signed with the debug/release certificate and printing the hash to the log. The snippet hashes each signature with SHA-1 ("SHA") and logs the digest as Base64. The Maps console expects the same digest as colon-separated hexadecimal.
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.package.name", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String hash= new String(Base64.encode(md.digest(), 0));
Log.e("hash", hash);
}
} catch (NameNotFoundException e1) {
Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("no such algorithm", e.toString());
} catch (Exception e) {
Log.e("exception", e.toString());
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents