简体   繁体   English

使用Android SDK为Facebook登录启用Chrome自定义标签

[英]Enabling Chrome Custom Tabs for Facebook login using Android SDK

I am using Facebook SDK version 4.11.0 in my app. 我在我的应用程序中使用Facebook SDK版本4.11.0。

As per the steps outlined on the Official docs page , I have added following things inside manifest file to enable Chrome Custom Tabs. 根据官方文档页面上列出的步骤,我在清单文件中添加了以下内容以启用Chrome自定义标签。

<activity
    android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />

<activity
    android:name="com.facebook.CustomTabActivity"
    android:exported="true">
    <intent-filter>
       <action android:name="android.intent.action.VIEW" />
       <category android:name="android.intent.category.DEFAULT" />
       <category android:name="android.intent.category.BROWSABLE" />
       <data android:scheme="@string/fb_login_protocol_scheme" />
    </intent-filter>
</activity>

<meta-data
    android:name="com.facebook.sdk.ApplicationId"
    android:value="@string/app_id" />

fb_login_protocol_scheme is added to strings.xml with value 'fb+app_id' fb_login_protocol_scheme被添加到strings.xml ,其值为'fb + app_id'

Authentication process is working fine without any issue. 身份验证过程正常,没有任何问题。
Only concern is when I click on login button, the login dialog doesn't opens up in Chrome Custom Tabs but in the usual webview dialog format. 唯一值得关注的是,当我点击登录按钮时,登录对话框不会在Chrome自定义选项卡中打开,而是以通常的webview对话框格式打开。

Is there something here missing to be added to the project to enable Chrome Custom Tabs? 此处是否缺少某些内容可添加到项目中以启用Chrome自定义标签?

You can check why Chrome Custom Tabs doesn't work with this snippet: 您可以查看Chrome自定义标签无法使用此代码段的原因:

private static final String CUSTOM_TABS_SERVICE_ACTION = "android.support.customtabs.action.CustomTabsService";
private static final String CHROME_PACKAGE = "com.android.chrome";

private boolean isCustomTabsAllowed(Context context) {
    boolean isCustomTabsAllowed = true;

    if (!isCustomTabsEnabled(context)) {
        Log.d(TAG, "isCustomTabsEnabled false");
        isCustomTabsAllowed = false;
    }

    if (!isChromeCustomTabsSupported(context)) {
        Log.d(TAG, "isChromeCustomTabsSupported false");
        isCustomTabsAllowed = false;
    }

    if (!Validate.hasCustomTabRedirectActivity(context)) {
        Log.d(TAG, "hasCustomTabRedirectActivity false");
        isCustomTabsAllowed = false;
    }

    return isCustomTabsAllowed;
}

private boolean isCustomTabsEnabled(Context context) {
    final String appId = Utility.getMetadataApplicationId(context);
    final Utility.FetchedAppSettings settings = Utility.getAppSettingsWithoutQuery(appId);
    return settings != null && settings.getCustomTabsEnabled();
}

private boolean isChromeCustomTabsSupported(final Context context) {
    Intent serviceIntent = new Intent(CUSTOM_TABS_SERVICE_ACTION);
    serviceIntent.setPackage(CHROME_PACKAGE);
    List<ResolveInfo> resolveInfos =
            context.getPackageManager().queryIntentServices(serviceIntent, 0);
    return !(resolveInfos == null || resolveInfos.isEmpty());
}

These are the methods called by the Facebook SDK before launch the Chrome Custom Tabs, so simply calling isCustomTabsAllowed you can understand what's wrong with your app. 这些是在启动Chrome自定义标签之前由Facebook SDK调用的方法,因此只需调用isCustomTabsAllowed即可了解您的应用程序出了什么问题。

If isCustomTabsEnabled is false there is some problem in the configuration of your app. 如果isCustomTabsEnabled为false,则表明您的应用配置存在问题。 Verify on Facebook console under App Review section that the app is live and available to the public. App Review下的Facebook控制台上验证应用程序是否正常并可供公众使用。

If isChromeCustomTabsSupported is false probably you have an older version of Chrome that doesn't support the Chrome Custom Tabs, try to update to the last version of Chrome. 如果isChromeCustomTabsSupported为false,则可能是您的旧版Chrome不支持Chrome自定义标签,请尝试更新到最新版本的Chrome。

If hasCustomTabRedirectActivity is false there are some issues in the integration, verify that you correctly followed all the steps indicated in the guide . 如果hasCustomTabRedirectActivity为false,则集成中存在一些问题,请验证您是否正确遵循了指南中指示的所有步骤。 Also verify that the APP_ID is the same used in the string facebook_app_id otherwise the login dialog won't use the Chrome Custom Tabs. 同时验证APP_ID与字符串facebook_app_id使用的相同,否则登录对话框将不使用Chrome自定义选项卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android应用程序自定义用户注册和使用Facebook SDK的Cookie登录 - Android app custom user registration and login with cookie using facebook sdk 如何在Android中使用Facebook sdk 4.7.0和自定义Google Plus登录按钮制作自定义Facebook登录按钮 - How to make a custom facebook login button using Facebook sdk 4.7.0 in android and a custom Google Plus login button 适用于Android的Facebook SDK 3-使用facebook应用程序登录 - Facebook SDK 3 for Android - Login using facebook app 在Android项目中启用Facebook SDK - Enabling Facebook SDK in an Android Project Android facebook sdk 3.0 通过自定义按钮登录 - Android facebook sdk 3.0 login by custom button Android Facebook sdk登录避免了webview客户端弹出,并使用具有登录名和密码的自定义活动 - Android Facebook sdk login avoiding the webview client popup and using a custom Activity with login and password Facebook Android SDK 3.5中的自定义Facebook登录按钮图像 - Custom Facebook login button image in Facebook Android SDK 3.5 登录问题使用facebook sdk 3.0 for android - Login Issue using facebook sdk 3.0 for android 如何在android中使用sdk 4.1.0登录facebook? - How to login facebook using sdk 4.1.0 in android? 无法使用新的Android sdk登录Facebook? - Unable to Login to facebook using new Android sdk?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM