Android allows you to open a local app (app) and get the data from your browser by clicking the link in the browser

Source: Internet
Author: User

Http://itindex.net/blog/2014/11/07/1415353560000.html

Click the URL link in your browser to launch a specific app.

First make the HTML page, the page content format is as follows:

This sentence will be all right.

The meanings of each item are as follows:

Scheme: Identify the app that starts. ※ The following details are described

Host: Proper description

Path: The key※ required to pass the value is not also available

Query: Get the value of key and Value※ no also can

Write it well as a test, as follows:

<a href= "myapp://jp.app/openwith?name=zhangsan&age=26" > Start Application </a>  

Next comes the Android side.
First, add the following to the main activity of Androidmanifest.xml. (given when activating activity)

* Items must be added

<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= "MyApp" android:host= "Jp.app" android:pathprefix= "/openwith"/>  </ Intent-filter>

The contents of the HTML description are added to <data .../>.
The required content is only scheme, and no other content app can be launched.

※ Note: The contents of Intent-filter "Android.intent.action.MAIN" and "Android.intent.category.LAUNCHER" are 2, and cannot be mixed with this additional content.
So, if you join the same activity, do this as follows, or it will cause the app icon to disappear on the desktop.

<intent-filter>      <action android:name= "Android.intent.action.MAIN"/>      <category android: Name= "Android.intent.category.LAUNCHER"/>  </intent-filter>  <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= "MyApp" android:host= "Jp.app" android:pathprefix= "/openwith"/>  

In that case, no problem.

Next, add the following code where the activity needs to be valued, and I'll write it directly in the OnCreate function:

Intent I_getvalue = Getintent ();
String action = I_getvalue.getaction ();

if (Intent.ACTION_VIEW.equals (ACTION)) {
Uri uri = I_getvalue.getdata ();
if (uri! = null) {
String name = Uri.getqueryparameter ("name");
String age= uri.getqueryparameter ("Age");
}
}

This will get the value passed to the URL.

Android allows you to open a local app (app) and get the data from your browser by clicking the link in the browser

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.