Objective:
Recently, the rapid development of the company's business, a single project is no longer suitable for the development needs of the company, so began to promote the company's app business components, is honored to take the lead to do this matter, after research to achieve a modular communication program through the URL schema, so think now or in the pre-research stage, It is necessary to understand the URL Schema first to see how it is used? In fact, before doing hybrid mixed programming when contact with the URL Schema, always come to the point is not unfamiliar, today to review and summarize.
What is a URL Schema?
The scheme in Android is a kind of in-page jump protocol, is a very good implementation mechanism, by defining their own scheme protocol, can be very convenient to jump to the various pages of the app, through the scheme protocol, the server can be customized to tell the app to jump that page, You can customize the jump page via the notification bar message, which can be redirected through the H5 page.
URL Schema Application Scenario:
A client app can register a URL scheme with the operating system that is used to launch the app from a browser or other app. The specified URL field allows the app to open certain pages directly after it has been called, such as the Product Details page, the Activity Details page, and so on. You can also perform certain actions, such as completing payments, and so on. You can also directly invoke a page within the app by using an HTML page. The URL schema usage scenario is broadly divided into the following categories:
- Server issued a jump path, the client according to the server issued a jump path to jump to the corresponding page
- H5 page Click on the anchor point, depending on the anchor point specific jump path app side jump specific page
- The app side receives the server-side push notification bar message and jumps to the relevant page according to the message's Click Jump Path.
- The app jumps to another app-specific page based on the URL
URL Schema Protocol format:
Let's start with a full URL Schema protocol format:
xl://goods:8888/goodsdetail?goodsid=10011002
Through the above path Schema, Host, port, path, query all contained, basically the use of the path is usually the case.
- XL represents the schema agreement name
- Goods represents which address field the schema acts on
- Goodsdetail represents the page specified by the schema
- Parameters passed by Goodsid delegates
- 8888 The port number that represents the path
URL schema How to use: 1.) Add <intent-filter/> Set schema to <activity/> tags in androidmanifest.xml
<ActivityAndroid:name=". Goodsdetailactivity "Android:theme= "@style/apptheme"> <!--You must add a intent filter if you want to successfully tune the app on another app - <Intent-filter> <!--part of the agreement, casually set - <DataAndroid:scheme= "XL"Android:host= "goods"Android:path= "/goodsdetail"Android:port= "8888"/> <!--The following lines also have to be set - <categoryAndroid:name= "Android.intent.category.DEFAULT"/> <ActionAndroid:name= "Android.intent.action.VIEW"/> <categoryAndroid:name= "Android.intent.category.BROWSABLE"/> </Intent-filter> </Activity>
2.) Get the parameters of the schema jump
Uri uri =getintent (). GetData ();if(URI! =NULL) { //Full URL InformationString URL =uri.tostring (); LOG.E (TAG,"URL:" +URI); //Scheme SectionString scheme =Uri.getscheme (); LOG.E (TAG,"Scheme:" +scheme); //Host SectionString host =Uri.gethost (); LOG.E (TAG,"Host:" +host); //Port Section intPort =Uri.getport (); LOG.E (TAG,"Host:" +port); //access to road strengthString Path =Uri.getpath (); LOG.E (TAG,"Path:" +path); List<String> pathsegments =uri.getpathsegments (); //Query SectionString query =Uri.getquery (); LOG.E (TAG,"Query:" +query); //gets the specified parameter valueString Goodsid = Uri.getqueryparameter ("Goodsid"); LOG.E (TAG,"Goodsid:" +goodsid);}3.) Call mode
On the Web page
<href= "xl://goods:8888/goodsdetail?goodsid=10011002"> Open Item details </ a >
Native invocation
New Intent (Intent.action_view,uri.parse ("xl://goods:8888/goodsdetail?goodsid=10011002")); StartActivity (intent);
4.) How to determine if a schema is valid
Packagemanager Packagemanager =new Intent (Intent.action_view, Uri.parse ("xl://goods:8888/ goodsdetail?goodsid=10011002 ")); List<ResolveInfo> activities = packagemanager.queryintentactivities (Intent, 0); boolean isValid = !activities.isempty (); if (isValid) { startactivity (intent);}
Summarize:
The basic use of the schema is so much, the other uses in the future when used to summarize.
Android Business Component URL schema use