Android Facebook login without Facebook login button

…衆ロ難τιáo~ 提交于 2020-01-04 04:39:07

问题


I want login with facebook without using Facebook Login Button. so i applied click event on default android button.

But i got error cannot resolve method logInWithReadPermissions(..)..

here is my code. Any help will appreciated

btnFBLogin.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v)
       {    
            LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"));// here giving error can not resolve method
       }
});

回答1:


You are currently passing reference of button

But you need to pass reference of Activity

Please use the below code that might help you.

LoginManager.getInstance().logInWithReadPermissions(LoginActivity.this, Arrays.asList("public_profile", "email"));



回答2:


Use the

LoginActivity.this // name of the activity and `.this`

instead of this in Button onClick() function. If you using this in this case it means you referring to the Button not the Activity. Because this refers to the subsequent parent which is in this case Button.
If you use the same code in onCreate() method (not in any click listener etc.) that's fine Because in that case this refers to the activity.



来源:https://stackoverflow.com/questions/32605127/android-facebook-login-without-facebook-login-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!