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

Today, the boss gave me a need to ask me to investigate, he has tested the iOS platform is available, the requirement is simple is to enter a URI in the system browser to open the corresponding app.

For example, you enter in the system browser of iOS: tel://123, will jump to call page and dial number is 123, like this command, eldest brother he used the millet phone test, found can, so he thought that Android is also possible, But when I use Samsung and HTC phone test found no, this time the boss is tangled, but I personally think, we all know that Xiaomi phone is imitation of iOS, did not expect to imitate so. So the boss asked me to study, I looked up the information, found the solution is as follows

First on a code, the landlord verification is absolutely can be used and also relatively clear code! PS: Let's play it first, the majority of third-party browsers cannot succeed. )

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.

—————————————————————————————————— I'm a split line ————————————————————————————————————

Code copy is finished, is not very surprised to find in the browser input

Myapp://jp.app/openwith?name=zhangsan&age=26

Is it 404, not open?

Landlord you This is not a lie! Lou Zhu, you son of a.

Sir, don't be impatient, do you see what browser you are using? UC, Cheetah, open gate? Give up, try the system comes with a browser or Google browser bar. Must be able to succeed, can not succeed again to pit me. Ha ha.

Also, if your phone is millet, then congratulations, download Google Browser is not used! Xiaomi system default browser is the imitation of Google, but there are a lot of deleted mechanisms are completely rejected, various crashes error, need to download the Valley

Song Framework to assist (360 mobile phone assistant to search), even if the Google frame download can not guarantee that Google browser to use, my Xiaomi 1 test can not be used, rice 2 .... It is recommended that you do not use millet phone test, sinkhole Ah!

—————————————————————————————————— I'm a split line ————————————————————————————————————

Suddenly feel good sad, finally get this skill, but can not be used by third-party browser. It's a tragedy that most of the Android browsers are occupied by third parties.

Then let's talk about why third-party browsers don't succeed. First of all, I found the UC browser, and if you use your own scheme instead of HTTP, UC will default to adding http://In front of your scheme. This is too much of a dad. Other browsers don't see the same situation. After discovering the problem, I tried to change my scheme to HTTP. Then ran again with anticipation, and the result was a pit-father. So I think it would be a third-party browser to address the URL. Here, I have no alternative. I tested UC, cheetah, open Gate, these 3 are not supported. The system comes with and Google Chrome is supported.

Finally, add a clue, in the browser search Baidu application. After entering their pages, they can be implemented in various browsers to launch already installed local apps. After seeing this, I read the source code of their page.

Here they add a data-sentintent label, see here, should be able to determine that the third-party browser should be the default does not support hair intent, only one. According to the front end, this tag should be customized. When we look at the source at the front, we find this.

So the final result should be the Baidu side is a port, and then in the application to enable a service, to listen to this port, to obtain this intent. That's probably the idea. But the landlord did not actually go to operate. Project time is tight, too troublesome. Right, Baidu this is to have integrated their inapp this SDK.

Attach StackOverflow Two RELATED links: Http://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app

Http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser

Android allows you to open the Local app (app) and get the data from the browser via a browser click on the link (go)

Related Article

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.