简体   繁体   中英

Android Facebook login without Facebook login button

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
       }
});

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"));

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM