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: