How to generate hash key to integrate facebook login

/** Getting or generate facebook hash key **/


public void getHash() {
        try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    getPackageName(),
                    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 (PackageManager.NameNotFoundException e) {
            Log.d("pkg", e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            Log.d("alg", e.getMessage());
        }
    }

Comments

  1. @Override
    public void onBackPressed() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
    drawer.closeDrawer(GravityCompat.START);
    }
    else {
    int fragments = getSupportFragmentManager().getBackStackEntryCount();
    if (fragments == 1) {
    finish();
    } else if (getFragmentManager().getBackStackEntryCount() > 1) {
    getFragmentManager().popBackStack();
    } else {
    super.onBackPressed();
    }
    }
    }

    ReplyDelete

Post a Comment