Code Monkey home page Code Monkey logo

chrome-custom-tab-helper's Introduction

ChromeCustomTabHelper

Convenient helper class to launch web page through Google Chrome Custom Tab.

Download

How to install

  1. Add jcenter() to your the root build.gradle allprojects scope.
allprojects {
    repositories {
        google()
        jcenter()    // <== add this one
    }
}
  1. Add the dependency

Stable version (Android X)

minSdkVersion is 21

implementation "liou.rayyuan.chromecustomtabhelper:chrome-custom-tab-helper:[latest-version]"

How to use

  1. Create a new object for ChromeCustomTabHelper
    private val chromeCustomTabHelper = ChromeCustomTabsHelper() 
  1. Warm up the custom tab service in the onResume() state of Activity or Fragment
    And don't forget to cool down in the onStop() state. You can pick up your prefer browser in the second parameter.
    Current support browsers: Chrome, Firefox and Samsung internet.
    override fun onResume() {
        super.onResume()
        chromeCustomTabHelper.bindCustomTabsServices(this, Browsers.CHROME, url)
    }

    override fun onStop() {
        super.onStop()
        chromeCustomTabHelper.unbindCustomTabsServices(this)
    }
  1. When it need to open web tab.
    val builder = CustomTabsIntent.Builder()
    // here custom your tab styles and behavior
    val chromeCustomTabIntent = builder.build()
    ChromeCustomTabsHelper.openCustomTab(this, Browsers.CHROME, chromeCustomTabIntent, uri) { activity, uri ->
        // if chrome is not install, fallback to standard webview 
        // or just send an intent to someone can handle
        val intent = Intent(Intent.ACTION_VIEW)
        intent.data = uri
        startActivity(intent)
    }

That's it!

chrome-custom-tab-helper's People

Contributors

yuanliou avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

thexxturboxx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.