我在我的应用程序中使用Facebook SDK版本4.11.0。
根据Official docs page中列出的步骤,我在清单文件中添加了以下内容以启用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
,其值为&#39; fb + app_id&#39;
身份验证过程正常运行,没有任何问题 唯一值得关注的是,当我点击登录按钮时,登录对话框不会在Chrome自定义标签中打开,而是以通常的网络视图对话框格式打开。
此处是否缺少某些内容可添加到项目以启用Chrome自定义标签?
答案 0 :(得分:10)
您可以查看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());
}
这些是在启动Chrome自定义标签之前由Facebook SDK调用的方法,因此只需致电isCustomTabsAllowed
即可了解您的应用有什么问题。
如果isCustomTabsEnabled
为false,则说明您的应用配置存在问题。在 App Review 部分的Facebook控制台上验证该应用程序是否正常并可供公众使用。
如果isChromeCustomTabsSupported
为false,则可能是您的旧版Chrome不支持Chrome自定义标签,请尝试更新到最新版本的Chrome。
如果hasCustomTabRedirectActivity
为false,则集成中存在一些问题,请验证您是否正确执行了guide中指示的所有步骤。同时验证APP_ID与字符串facebook_app_id
中使用的相同,否则登录对话框将不会使用Chrome自定义标签。