Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.meierjan:simple-chrome-custom-tabs:-SNAPSHOT'
}
dependencies {
implementation("com.github.meierjan:simple-chrome-custom-tabs:-SNAPSHOT")
}
<dependency>
<groupId>com.github.meierjan</groupId>
<artifactId>simple-chrome-custom-tabs</artifactId>
<version>-SNAPSHOT</version>
</dependency>
libraryDependencies += "com.github.meierjan" % "simple-chrome-custom-tabs" % "-SNAPSHOT"
:dependencies [[com.github.meierjan/simple-chrome-custom-tabs "-SNAPSHOT"]]
SimpleChromeCustomTabs will help you with that.
SimpleChromeCustomTabs provides easy integration of Chrome Custom Tabs into your project. Just connect it to your activity, and navigate to the external website styling your tab as you wish. Moreover with Custom Tabs the navigation can be nearly instantaneous!
More information about Chrome Custom Tabs available at: https://developer.chrome.com/multidevice/android/customtabs
To start using this library, add these lines to the build.gradle
of your project:
repositories {
maven {
url "http://dl.bintray.com/novoda/maven"
}
}
dependencies {
compile 'com.novoda:simple-chrome-custom-tabs:0.1.3'
}
1) Initialize SimpleChromeCustomTabs
, you only have to this once.
SimpleChromeCustomTabs.initialize(context);
2) Connect SimpleChromeCustomTabs
to your Activity
as soon as it is resumed.
@Override
public void onResume() {
super.onResume();
SimpleChromeCustomTabs.getInstance().connectTo(this);
}
And don't forget to disconnect when the Activity
is paused.
@Override
public void onPause() {
SimpleChromeCustomTabs.getInstance().disconnectFrom(this);
super.onPause();
}
3) Navigate!
Uri url = ANY_WEBSITE_URL;
NavigationFallback fallback = ANY_FALLBACK_MECHANISM; //In case something goes wrong.
IntentCustomizer customizer = ANY_INTENT_CUSTOMIZER; //To theme your tab.
SimpleChromeCustomTabs.getInstance().withFallback(fallback)
.withIntentCustomizer(customizer)
.navigateTo(url, activity);
And voilà!!
External Browser | SimpleChromeCustomTabs
--- | ---
|
Note: Check the extended demo for further usage examples.
Here are a list of useful links: