Openssl is not recognized as an internal or external command

后端 未结 15 1796
轻奢々
轻奢々 2020-11-28 00:59

I wish to generate an application signature for my app which will later be integrated with Facebook. In one of Facebook\'s tutorials, I found this command:

k         


        
15条回答
  •  执念已碎
    2020-11-28 02:01

    it's late answer but it will help to lazy people like me.. add this code to your Application class, there is no need to download openssl and no need to set the path.. only need is just copy this code.. and keyHash will generated in log.

    import com.facebook.FacebookSdk;
    public class MyApplication extends Application {
    
        @Override
        public void onCreate() {
            super.onCreate();
            FacebookSdk.sdkInitialize(getApplicationContext());
            AppEventsLogger.activateApp(this);
            printKeyHash();
        }
    
        private void printKeyHash() {
            try {
                PackageInfo info = getPackageManager().getPackageInfo(
                        getPackageName(), PackageManager.GET_SIGNATURES);
                for (Signature signature : info.signatures) {
                    MessageDigest md = MessageDigest.getInstance("SHA");
                    md.update(signature.toByteArray());
                    Log.i("KeyHash:",
                            Base64.encodeToString(md.digest(), Base64.DEFAULT));
                }
            } catch (PackageManager.NameNotFoundException e) {
                Log.e("jk", "Exception(NameNotFoundException) : " + e);
            } catch (NoSuchAlgorithmException e) {
                Log.e("mkm", "Exception(NoSuchAlgorithmException) : " + e);
            }
        }
    }
    

    and do not forget add MyApplication class in manifest:

    
    

提交回复
热议问题