Preface:
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 component, I am honored to take the lead to do this thing, through research to achieve the component of the communication program through the URL Schema, so think now or in the It is necessary to understand the URL Schema first to see how it is used? In fact, before doing hybrid mixed programming in contact with the URL Schema, the total came to be not unfamiliar, today to review the summary.
What is a URL Schema?
Scheme in Android is a kind of intra-page jump protocol, a very good implementation mechanism, by defining its own scheme protocol, can be very convenient to jump to the various pages in the app, through scheme protocol, the server can be customized to tell app to jump that page, Can be customized through the Notification bar message jump page, you can through the H5 page jump page and so on.
URL Schema Application scenario:
Client applications can register a URL scheme with the operating system that is used to start the application from a browser or other application. By specifying the URL field, you can have the application open some specific pages directly after being tuned, such as the Product Details page, the Activity Details page, and so on. You can also perform certain specified actions, such as completing payments. You can also directly invoke a page in the app by using an HTML page. The overall URL schema usage scenario is roughly divided into the following categories:
• The server issued a jump path, the client according to the server issued a jump path to jump the corresponding page
h5 page Click Anchor Point, according to the anchor point specific jump path app end jump specific page
app end of the server received a push notice bar message, according to the message of the click Jump path Jump related pages
app jump to another app page based on URL
URL Schema Protocol format:
First, a complete URL Schema protocol format:
xl://goods:8888/goodsdetail?goodsid=10011002
Through the above path Schema, Host, port, path, query all contains, basically use the path is such a son.
XL represents the schema protocol name
goods represents which address field the schema acts on
Goodsdetail represents the page specified by the schema
Goodsid represents the parameters passed
• 8888 The port number that represents the path
How the URL schema uses:
1. Add <intent-filter/> Set schema to <activity/> tags in androidmanifest.xml
<activity
android:name= ". Goodsdetailactivity "
android:theme=" @style/apptheme
<!--to be able to successfully tune the app on another app, you must add intent filter-->
<intent-filter>
<!--Agreement section, set up-->
<data android:scheme= "XL" android:host= "goods" arbitrarily Android:path= "/goodsdetail" android:port= "8888"/>
<!--The following lines must also be set up--> <category android:name=
"Android.intent.category.DEFAULT"/>
<action android:name= "Android.intent.action.VIEW"/>
< Category android:name= "Android.intent.category.BROWSABLE"/>
</intent-filter>
</activity >
2.) Get the parameters of schema jump
Uri uri = getintent (). GetData ();
if (URI!= null) {
//complete URL information
String URL = uri.tostring ();
LOG.E (TAG, "url:" + uri);
Scheme part
String scheme = Uri.getscheme ();
LOG.E (TAG, "scheme:" + scheme);
Host part
String host = Uri.gethost ();
LOG.E (TAG, "host:" + host);
Port part
int port = Uri.getport ();
LOG.E (TAG, "host:" + port);
Access to road strength
String Path = Uri.getpath ();
LOG.E (TAG, "path:" + path);
list<string> pathsegments = uri.getpathsegments ();
Query part
String query = Uri.getquery ();
LOG.E (TAG, "query:" + query);
Gets the specified parameter value
String goodsid = Uri.getqueryparameter ("Goodsid");
LOG.E (TAG, "Goodsid:" + goodsid);
}
3.) Calling Mode
On the Web page
Copy Code code as follows:
<a href= "xl://goods:8888/goodsdetail?goodsid=10011002" > Open Product Details </a>
Native call
Copy Code code as follows:
Intent Intent = new Intent (Intent.action_view,uri.parse ("xl://goods:8888/goodsdetail?goodsid=10011002"));
StartActivity (Intent);
4. How to determine whether a schema is valid
Packagemanager Packagemanager = Getpackagemanager ();
Intent Intent = 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 schema is so much, other use in the future when used to make a summary.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.