gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:04:06 24 4
gpt4 key购买 nike

我在我的应用中使用 Facebook SDK 版本 4.11.0。

按照 Official docs page 上列出的步骤,我在 list 文件中添加了以下内容以启用 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 添加到 strings.xml 中,值为 'fb+app_id'

身份验证过程工作正常,没有任何问题。
唯一担心的是,当我点击登录按钮时,登录对话框不会在 Chrome 自定义选项卡中打开,而是以通常的 webview 对话框格式打开。

这里是否缺少要添加到项目中以启用 Chrome 自定义标签的内容?

最佳答案

您可以检查为什么 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());
}

这些是 Facebook SDK 在启动 Chrome 自定义标签之前调用的方法,因此只需调用 isCustomTabsAllowed,您就可以了解您的应用程序出了什么问题。

如果 isCustomTabsEnabled 为 false,则您的应用程序配置存在问题。在 Facebook 控制台的App Review 部分下验证该应用程序是否已上线并可供公众使用。

如果 isChromeCustomTabsSupported 为 false,可能是您使用的是不支持 Chrome 自定义标签的旧版 Chrome,请尝试更新到最新版本的 Chrome。

如果 hasCustomTabRedirectActivity 为 false,则表示集成中存在一些问题,请验证您是否正确执行了 guide 中指示的所有步骤.还要验证 APP_ID 是否与字符串 facebook_app_id 中使用的相同,否则登录对话框将不会使用 Chrome 自定义选项卡。

关于android - 使用 Android SDK 为 Facebook 登录启用 Chrome 自定义标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37023442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com