This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together

1. What is URL Scheme?

Simply speaking, it is an in-page jump protocol in Android to facilitate the in-page jump of APP

2. When to use it

  1. When the server delivers the forward path, the client redirects to the corresponding page
  2. H5 Click the tracing point on the page and jump to the specific page on the APP end according to the specific redirecting path of the tracing point
  3. The APP side receives the PUSH notification message sent by the server side and redirects relevant pages according to the redirect path of the message
  4. APP jumps to another APP specified page based on URL

3. Protocol format

zymobi://3g2win:9999/macthDetail? macthId=222&time=10001Copy the code
scheme Indicates the Schema protocol name zymobi
host Represents the address domain on which Schema is applied 3g2win
port Represents the port number of the path 9999
path Represents the Schema specified page /macthDetail
Represents parameters passed ? macthId=222&time=10001

4. How to use it in the APP

Add intent-filter Schema to the activity TAB in androidmanifest.xml

 <activity android:name=".SecondActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="zymobi"
                    android:host="3g2win"
                    android:port="9999"
                    android:path="/macthDetail"
                    />

            </intent-filter>

        </activity>
Copy the code

Note:

<action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category  android:name="android.intent.category.BROWSABLE"/>Copy the code

5. How to call it

1. Calling in HTML is very simple

<a href="zymobi://3g2win:9999/macthDetail? MacthId =222&time=10001"> Open the page specified by the source app </a>Copy the code

2. It is also easy to call in a source application

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("zymobi://3g2win:9999/macthDetail? macthId=222&time=10001")); startActivity(intent);Copy the code

6. Obtain the URI and parameters on the source page

 Intent intent = getIntent();
        Uri data = intent.getData();  //
        String action = intent.getAction();
        String scheme = intent.getScheme();
        Set<String> categories = intent.getCategories();
        Log.e("TAG", "data==========="+data);
        Log.e("TAG", "action==========="+action);
        Log.e("TAG", "categories==========="+categories);
        Log.e("TAG", "DataString==========="+intent.getDataString());
        Log.e("TAG", "==============================");
        Log.e("TAG", "scheme==========="+scheme);
        Log.e("TAG", "id ==========="+data.getQueryParameterNames());
        Log.e("TAG", "host==========="+data.getHost());
        Log.e("TAG", "path==========="+data.getPath());
        Log.e("TAG", "port==========="+data.getPort());
Copy the code

The output

4-11 18:13:56. 335, 5198-5198 / com. Phone. Myapplication E/TAG: data = = = = = = = = = = = zymobi: / / 3 g2win: 9999 / macthDetail? GoodsId = 10011002 & time = 1111 04-11 18:13:56. 335, 5198-5198 / com. Phone. Myapplication E/TAG: Action = = = = = = = = = = = android. The intent. The action. The VIEW 04-11 18:13:56. 335, 5198-5198 / com. Phone. Myapplication E/TAG: Categories = = = = = = = = = = = null 04-11 18:13:56. 335, 5198-5198 / com. Phone. Myapplication E/TAG: DataString = = = = = = = = = = = zymobi: / / 3 g2win: 9999 / macthDetail? GoodsId = 10011002 & time = 1111 04-11 18:13:56. 335 5198-5198/com.phone.myapplication E/TAG: = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 4-11 18:13:56. 335, 5198-5198 / com. Phone. Myapplication E/TAG: Scheme = = = = = = = = = = = zymobi 04-11 18:13:56. 335, 5198-5198 / com. Phone. Myapplication E/TAG: Id = = = = = = = = = = = [time] goodsId, 04-11 18:13:56. 335, 5198-5198 / com. Phone. Myapplication E/TAG: The host = = = = = = = = = = = 3 g2win 04-11 18:13:56. 335, 5198-5198 / com. Phone. Myapplication E/TAG: Path = = = = = = = = = = = / macthDetail 18:13:56. 04-11, 335, 5198-5198 / com. Phone. Myapplication E/TAG: port = = = = = = = = = = = 9999Copy the code

The specific meaning can be compared with the parameters passed in

7. Check whether the Schema is valid

To check whether the Schema is valid, you can also check whether the application is installed (before making sure that the application to be started has scheme configured).

App source determines whether Sheme is valid

Intent intent = newIntent(Intent.ACTION_VIEW, Uri.parse("zymobi://3g2win:9999/macthDetail? macthId=222&time=10001")); List<ResolveInfo> activities =packageManager.queryIntentActivities(intent, 0); boolean isValid = ! activities.isEmpty(); Toast.makeText(this,isValid+"",Toast.LENGTH_LONG).show();Copy the code