问题
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