Android Facebook SDK 3.23.0 - FB Login on AndroidT

2019-02-27 09:20发布

问题:

Does anyone have any experience using the Facebook SDK to perform Facebook login on AndroidTV?

Since it's most often the case that an AndroidTV user won't have the actual Facebook app installed on the AndroidTV device, the Facebook SDK will open a WebView to allow the user to enter his Facebook credentials and login.

The issue is the webview that gets displayed doesn't respond to d-pad actions and the fields to enter text don't indicate they are selected.

Am I to assume that Facebook login for AndroidTV just isn't possible using the standard Facebook SDK functionality?

回答1:

Correct. Also, Facebook API currently does not support Android TV. So it'll not be possible for you to build an app with Facebook Login on Android TV (unless you wanna write your own library for it). Hence, no D-Pad support and the messed up function of the text fields.



回答2:

This is taken directly from the documentation

Note: You can use the WebView class for logins to services like Google+ and Facebook.

I assume they are suggesting the use of a WebView, but not necessarily by means of the Facebook SDK (whose WebView might be custom/limited).



回答3:

For me this was very helpful:

The solution was to execute the following javascript on my WebView in

onPageFinished():

webView.loadUrl("javascript:document.getElementsByName('email')[0].focus();");

Obviously this will only work with the Facebook sign in screen, since they have a text field with name 'email'.

Source



回答4:

You can login with facebook on android tv, to do this you must first enable logging in from devices. Products - Facebook Login - Settings - Login from Devices - set to yes.

And for logging in you must use the DeviceLoginManager.

mDeviceLoginManager = DeviceLoginManager.getInstance();
        mDeviceLoginManager.registerCallback(mCallbackManager, facebookCallback);
 mDeviceLoginManager.setLoginBehavior(LoginBehavior.DEVICE_AUTH);
        mDeviceLoginManager.logInWithReadPermissions(this, Collections.EMPTY_LIST);

This will open a webview with a code.