Android scheme open App


  • URI=Uniform Resource Identifier: uniform resource identifier, which can uniquely identify a resource under a certain rule. For example, your ID number.
  • URL=Uniform Resource Locator: uniform resource locator, which can provide the path to find the resource. It is a subset of URIs and a URI implemented by location.

On www, every information resource has a unified and unique address on the Internet. This address is called URL, which refers to the network address.

2, Composition of URL

The general syntax format of URL is (those with square brackets [] are optional)

 agreement://Domain name: port number / directory / file name File suffix? Parameter = value # flag;parms=test_parms?uid=123&gid=45#fragment=009&fragment

  • Protocol protocol. The commonly used protocol is http
  • hostname host address, which can be domain name or IP address
  • Port the default port of http protocol is port 80. If it is not written, the default port is port 80
  • Path path the specified path of the network resource in the server
  • Parameter parameter if you want to pass a parameter to the server, enter it in this section
  • Query query string if you need to query the content from the server, edit it here
  • Fragment fragment the web page may be divided into different fragments. If you want to access the web page and directly reach the specified location, you can set it in this part


English meaning: scheme, format and strategy

It is a custom protocol, non-standard. In many cases, scheme is the name of the protocol, which defines how to obtain resources.


  • Encoding, query should be encoded, otherwise the direct parsing using the system method will fail

give an example

val url = "taobao://app/path?version=1.0&name=zhaoyanjun&open=true"
val uri = Uri.parse(url)
val scheme = uri.scheme
val host =
val path = uri.path
val version = uri.getQueryParameter("version")
val name = uri.getQueryParameter("name")
val open = uri.getBooleanQueryParameter("open", false)

Log.d("yu--", "scheme:$scheme")
Log.d("yu--", "host:$host")
Log.d("yu--", "path:$path")
Log.d("yu--", "version:$version name:$name")
Log.d("yu--", "open:$open")


D/yu--: scheme:taobao
D/yu--: host:app
D/yu--: path:/path
D/yu--: version:1.0 name:zhaoyanjun
D/yu--: open:true


Online encode:

query should be encoded, otherwise direct parsing using system methods will fail.

Why code? For example, I have two parameters:

  • Parameter 1: H5=
  • Parameter 2: version=1234

The complete scheme is as follows:


Next, get the parameters h5 and version respectively

val h5 = uri.getQueryParameter("h5")
val version = uri.getQueryParameter("version")


Obviously, the obtained value is not the correct value we want. Let's encode the whole query parameter to see the effect. The encoded scheme is as follows:

Before parameter 1 Coding:

After parameter 1 Coding:

Parameter 2 before coding: 1234
 Parameter 2 after coding: 1234

Combine the two parameters, and the complete scheme is as follows:


The relevant parameters of post removal are as follows:

D/yu--: scheme:taobao
D/yu--: host:app
D/yu--: path:/path
D/yu--: h5:
D/yu--: version:1234

h5 how to evoke app through scheme

Add scheme value in Activity

     <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />


            <!-- scheme start -->

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.APP_BROWSER" />

                    android:scheme="taobao" />

            <!-- scheme end -->


WEB end through call taobao://app/path?query1=1&query2=true You can open this Activity. scheme and host are required. In addition, it depends on the requirements.

Open via WEB

<!DOCTYPE html>
    <a href="taobao://app/path? Query1 = 1 & query2 = true "> Open app</a>

The core is the URL of a Schema protocol. scheme and host are necessary to open the APP page. The parameters passed can be obtained in the APP page.

Open through another APP

val intent = Intent(

Get scheme value

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {

        val uri =
        if (uri != null) {
            val scheme = uri.scheme
            val host =
            val path = uri.path
            val query1 = uri.getQueryParameter("query1")
            val query2 = uri.getQueryParameter("query2")

            Log.d("yu--", "scheme:$scheme")
            Log.d("yu--", "host:$host")
            Log.d("yu--", "path:$path")
            Log.d("yu--", "query1:$query1")
            Log.d("yu--", "query2:$query2")


Keywords: Android kotlin scheme

Added by darksniperx on Thu, 03 Mar 2022 08:29:23 +0200