How to Use Chrome Custom Tabs in Android? | androidx.browser:browser:1.5.0
Hi android developer in this blog I am share how to open an url in Chrome Custom Tabs using with androidx.browser dependencies. A majority of applications display various types of websites within their applications.
In order to display pages in Android there are many possibilities to show webpages within our Android application. The majority of developers prefer using WebView or redirect users to any browser in their app. However, opening the page in a browser and the display of a website in the Android WebView can be a difficult task is required.
Instead of making use of WebView as well as opening the page in a browser. You can use custom chrome tabs within the application that make this job simpler and less cumbersome. A lot of apps make use that allows custom Chrome tabs to redirecting users from their applications to any website using Chrome tabs that are custom. In this article, we’ll review the use of Custom Chrome tabs in Android.
Chrome Custom Tabs example in Android
By using Custom Chrome tab. Custom Chrome tab we will display a GFG website with a single press in our Android application. A example GIF is provided below from which you can get the idea of what we are planning to accomplish within this post. We use the Java programming language to build Chrome tabs on Android.
Step 1: Make a New Project
To create a brand new project using Android Studio Please refer to how to Start an A New Project using Android Studio. Make sure you choose Java for the language of programming.
Step 2: Add dependency to build.gradle(Module:app)
Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section.
dependencies { implementation "androidx.browser:browser:1.5.0" }
after adding dependancies sync your project for get dependencies method. After the Adding below code on any click listener where your want to open any URL in androidx.browser
public void openWebURL(String url) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.intent.setPackage("com.android.chrome"); customTabsIntent.launchUrl(getActivity(), Uri.parse(url)); }
Read More Tutorial