Last active
January 15, 2020 09:43
-
-
Save jonathanbcsouza/35a022ba10aaac193e217f9c96afa14e to your computer and use it in GitHub Desktop.
How to get a Hash to use in Facebook - Easy Way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1- Past this code within your onCreate. | |
// 2- Run your app. | |
// 3- Check your logcat! | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// Add code to print out the key hash | |
try { | |
PackageInfo info = getPackageManager().getPackageInfo( | |
getPackageName(), //Or replace to your package name directly, instead getPackageName() "com.your.app" | |
PackageManager.GET_SIGNATURES); | |
for (Signature signature : info.signatures) { | |
MessageDigest md = MessageDigest.getInstance("SHA"); | |
md.update(signature.toByteArray()); | |
Log.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); | |
} | |
} catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment