问题描述
我正在使用 CustomTabs 打开登录页面,但在我登录后,CustomTab 没有关闭并返回到应用程序。代码如下:
public static final String CUSTOM_TAB_PACKAGE_NAME = "com.android.chrome";
CustomTabsClient customTabsClient;
CustomTabsSession customTabsSession;
CustomTabsServiceConnection serviceConnection;
CustomTabsIntent customTabsIntent;
serviceConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(@NonNull ComponentName name,@NonNull CustomTabsClient client) {
customTabsClient = client;
customTabsSession = customTabsClient.newSession(new CustomTabsCallback() {
@Override
public void onNavigationEvent(int navigationEvent,@Nullable Bundle extras) {
Log.d("onNavigationEvent","onNavigationEvent: Code = " + navigationEvent);
switch (navigationEvent) {
case NAVIGATION_STARTED:
// Sent when the tab has started loading a page.
Log.e("NAVIGATION_STARTED","NAVIGATION_STARTED");
break;
case NAVIGATION_FINISHED:
Log.e("NAVIGATION_FINISHED","NAVIGATION_FINISHED");
// Sent when the tab has finished loading a page.
break;
case NAVIGATION_Failed:
Log.e("NAVIGATION_Failed","NAVIGATION_Failed");
// Sent when the tab Couldn't finish loading due to a failure.
break;
case NAVIGATION_ABORTED:
Log.e("NAVIGATION_ABORTED","NAVIGATION_ABORTED");
// Sent when loading was aborted by a user action before it finishes like clicking on a link
// or refreshing the page.
break;
}
}
@Override
public void onPostMessage(@NonNull String message,@Nullable
Bundle extras) {
super.onPostMessage(message,extras);
Log.i("callbacks","onPostMessage: " + message);
}
});
}
@Override
public void onServicedisconnected(ComponentName name) {
customTabsClient = null;
}
};
CustomTabsClient.bindCustomTabsService(getContext(),CUSTOM_TAB_PACKAGE_NAME,serviceConnection);
customTabsIntent = new CustomTabsIntent.Builder(customTabsSession)
.setToolbarColor(ContextCompat.getColor(getContext(),R.color.colorPrimary))
.setShowTitle(true)
.build();
customTabsIntent.launchUrl(getContext(),Uri.parse(url));
我正在清单中使用此深层链接返回应用程序:
<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:host="myURL"
android:pathPrefix="pathprefix"
android:scheme="https" />
</intent-filter>
此外,当我调试时 onNavigationEvent() 没有被调用。这个问题有什么解决方案吗? 谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)