FLAG_UPDATE_CURRENT ) įinally, we need to pass the bitmap, text, and pending intent created: CustomTabsIntent. getActivity ( this, requestCode, intent, PendingIntent. This pending intent needs to be passed to the Chrome Tabs intent builder: int requestCode = 100 PendingIntent pendingIntent = PendingIntent. Next, you need to create a pending intent (see this YouTube clip for more info), which is used to wake up your app when the user clicks on the icon. Next, create the intent: Intent intent = new Intent ( Intent. We will need to create a bitmap for use later: Bitmap bitmap = BitmapFactory. If you want to add a specific icon (such as the share icon) to the toolbar, you need to first should add the icon using New -> Image Asset (currently, Chrome Tabs do not support vector drawables so you should be using PNG files as your icons): addDefaultShareMenuItem () Adding custom icons Builder () // add share action to menu list builder. However, you can add a default one to the menu item list: CustomTabsIntent. Adding a share actionīy default, a Chrome tab does not include share action in the toolbar. For this reason, see this guide for how to include the design support library to leverage a new ContextCompat API. Normally, context.getResources().getColor()) can be used, but in Android API 23 this method has been deprecated. If you wish to set the toolbar color, you can use the setToolbarColor() method in the builder class: CustomTabsIntent. If you wish to add custom icons or actions to the menu, you will need to create pending intents to do so. Configuring other optionsĬonfiguring additional options requires using the builder class. SESSION and .TOOLBAR_COLOR) that gets ignored if the default browser cannot process this information. The CustomTabsIntent simply launches an implicit intent ( ) and passes an extra data in the intent (i.e. If you do not have Chrome installed, the intent will launch the default browser installed on the device. build () // and launch the desired Url with CustomTabsIntent.launchUrl() customTabsIntent. Builder () // set toolbar color and/or setting custom actions before invoking build() // Once ready, call () to create a CustomTabsIntent CustomTabsIntent customTabsIntent = builder. The most basic example to launch a Chrome tab is through a custom intent as shown below: // Use a CustomTabsIntent.Builder to configure CustomTabsIntent. If you are supporting previous API, you can add to your manifest to force its use and check the API version at runtime and just use Chrome Custom tabs if its >= 16 Usage The library only works on API 16 (Jelly Bean) an above. If you are using an emulator, you must setup Google Play Services and install the Chrome app though the Play store.Īdd the Android Support Library for Chrome Custom Tabs as a dependency to your gradle build file: implementation ':customtabs:25.2.0' ![]() You will need to have the Chrome app installed on your phone. See this README for more ways to use Chrome Custom Tabs. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |