- , @pRaNaY. :
private static final String EXTRA_CUSTOM_TABS_TOOLBAR_COLOR = "android.support.customtabs.extra.TOOLBAR_COLOR";
private static final String PACKAGE_NAME = "com.android.chrome";
private CustomTabsClient mClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
warmUpChrome();
launchUrl();
}
private void warmUpChrome() {
CustomTabsServiceConnection service = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
mClient = client;
mClient.warmup(0);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mClient = null;
}
};
CustomTabsClient.bindCustomTabsService(getApplicationContext(),PACKAGE_NAME, service);
}
private void launchUrl() {
Uri uri = getIntent().getData();
if (uri == null) {
return;
}
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
customTabsIntent.intent.setData(uri);
customTabsIntent.intent.putExtra(EXTRA_CUSTOM_TABS_TOOLBAR_COLOR, getResources().getColor(R.color.red));
PackageManager packageManager = getPackageManager();
List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(customTabsIntent.intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resolveInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
if (TextUtils.equals(packageName, PACKAGE_NAME))
customTabsIntent.intent.setPackage(PACKAGE_NAME);
}
customTabsIntent.launchUrl(this, uri);
}
Gradle:
compile "com.android.support:customtabs:23.0.0"
:
hotUpChrome . deeplinks, , startUrl URI String . stackoverflow, .