Android allows you to click a link in a browser to open a local application (APP) and obtain the data transmitted by the browser.

Source: Internet
Author: User

Android allows you to click a link in a browser to open a local application (APP) and obtain the data transmitted by the browser.

Click the URL link in the browser to start a specific App.

First, create an HTML page. The page content format is as follows:

Start the application

This sentence is enough.

The meanings of each project are as follows:

Scheme: identifies the started App. ※Detailed descriptions

Host: Description

Path: the key Required for value passing. ※no key is required.

Query: Obtain the Key and Value of the Value. ※no.

As a test, write the following:

Start the application

Next is the Android client.
First, append the following content under MAIN Activity of AndroidManifest. xml. (Given when Activity is started)

※Required

             
        
        
    
 

Add HTML description content.
The required content is only scheme and can be started without any other content app.

※Note: The content of intent-filter [android. intent. action. MAIN] and [android. intent. category. LAUNCHER] cannot be mixed with the content appended this time.
Therefore, if you add the same Activity, follow these steps. Otherwise, the application icon disappears on the desktop.

             
    
   
             
        
        
    
  

In this case, there is no problem.

Next, add the following code where values are needed in the Activity. I wrote the code 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 ");
}
}

In this way, the value passed by the URL can be obtained.

---------------------------------- I am a split line ------------------------------------

Is it surprising that the code is copied in a browser?

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

Is it 404, cannot be opened?

You are not a lie! You bastard.

What is your browser? UC, Cheetah, ou Peng? Give up. Try the built-in browser or Google browser. You can certainly succeed. If you cannot, you can try again. Haha.


---------------------------------- I am a split line ------------------------------------

I suddenly felt so sad that it was hard to get this skill, but it could not be used by a third-party browser. In this era where most android browsers are occupied by third parties, it is a tragedy.

Next, let's talk about why a third-party browser cannot succeed. First, I found the UC browser. If you use your own scheme instead of http, uc will add http: // before your scheme by default ://. This is too bad. Other browsers do not see the same situation. After finding this problem, I tried to change my scheme to http. Then I ran it again with expectation, and it turned out to be a pitfall. So I wonder if the url is processed by a third-party browser. Here, I have no choice. I tested UC, Cheetah, and openg, but none of them are supported. The built-in system is supported by Google Chrome.

Finally, let's add another clue to search Baidu applications in the browser. After entering their pages, they can start installed local apps in various browsers. After seeing this, I read the source code of their page.

Here, a data-sentintent tag is added to their page. We can see that the third-party browser should not support sending intent by default, and only one of them can be set up. According to the frontend, this label should be customized. When we looked at the source code, we found this was the case.

Therefore, the final result is that Baidu has set up a port, and then enables a service in the application to listen to the port to obtain the intent. This is probably the idea. However, the landlord did not actually perform the operation. The project is too time-consuming. By the way, Baidu has integrated their inapp sdk.

Attached stackoverflow two 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

We have encountered such a requirement recently:
When a user clicks a button in the browser of the mobile phone, if the app already exists on the mobile phone, the app is opened directly. If the app is not installed, the app download page is switched. In details, click a button on the webpage to open a local Activity (if any) or open a url in a browser.

After checking the document, Android supports this:

Http://developer.android.com/guide/topics/manifest/data-element.html

Description: scheme: // host: port/pathOrPathPrefixOrPathPattern

The schema + host + port + (path or pathPrefix or pathPattern) defined here can combine an http link, contains the filter Activity, and can process this http link.

Implementation:

  • Webpage code

    Click this button:

    ?
    1 <aid="applink1"href="http://test.xx.com/demo/test.php"> Open a>

    In http://test.xx.com/demo/test.php, directly request xxxx.apkto download the file.

    • Activity Code

      Add the following filter to the target Activity:

      ?
      1234567891011 <intent-filter><actionandroid:name="android.intent.action.VIEW"/> <categoryandroid:name="android.intent.category.DEFAULT"/> <categoryandroid:name="android.intent.category.BROWSABLE"/> <dataandroid:host="test.xx.com "android:path="/demo/test.php"android:scheme="http"/> intent-filter>

      After the filter is added, the Activity can process http ://Test.xx.com/Demo/test. php. Click "start" in the browser to initiate a request for this URL. If this application is installed on the local machine, the system will pop up a selection asking you to open it in the browser, open the application, for example:


      If this application is not installed on the local machine, the terminal is directly opened 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.