我有几个用户,每个用户都有令牌。我需要的是使用CustomTabsIntent未经授权访问该网站。
private CustomTabsServiceConnection mConnection;
private CustomTabsSession customTabsSession;
private CustomTabsClient mClient;
launchFunction()
CustomTabsIntent customTabs = new CustomTabsIntent.Builder(getSession()).setToolbarColor(getResources().getCo lor(R.color.white))
.enableUrlBarHiding()
.setShowTitle(false)
.build();
customTabs.intent.putExtra(android.provider.Browser.EXTRA_HEADERS, token);
customTabs.intent.setData(Uri.parse(url));
customTabs.intent.setPackage("com.android.chrome");
customTabs.launchUrl(getContext(), Uri.parse(url));
getSession()
private CustomTabsSession getSession() {
CustomTabsServiceConnection service = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
mClient = client;
mClient.warmup(0);
CustomTabsSession.createMockSessionForTesting(name);
customTabsSession = mClient.newSession(new CustomTabsCallback() {
@Override
public void onNavigationEvent(int navigationEvent, Bundle extras) {
extras.putString("Set-Cookie", token);
customTabsSession.mayLaunchUrl(Uri.parse(url), extras, null);
}
});
}
@Override
public void onServiceDisconnected(ComponentName name) {
mClient = null;
}
};
CustomTabsClient.bindCustomTabsService(getContext(), PACKAGE_NAME, service);
return customTabsSession;
}