There are more and more Android programmers, and even in some areas there is a situation of oversupply in supply. From a general background, the Android ecosystem will gradually become more rational and will continue to update talents and development tools. Eclipse in the past few years was extremely popular. Now, with a good experience of Android studio, more and more people have moved to Android studio for development, so this is also a manifestation of diversity. After talking so much nonsense, what I want to express is that there is no problem with many people. The important thing is that I have the ability to do this job, constantly learn new technologies, and update myself.
Now let’s talk about how to open the APP in your mobile phone in HTML. This requirement is now being used more and more widely. For example, Taobao, Alipay payment, etc., all use this function, but how to implement it? I will use webview to simulate such a function. First, look at the code in HTML:
<!DOCTYPE HTML> <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <body> <a href="xiaopinggaiblog://xiappinggai/open">Open app</a><br/></body> </html>
Right, you read it right. Just a few lines of code, no js is used, nor css is used. The (/a) tag is a hyperlink tag. I believe that people with some basic understanding can understand this. The important thing is to look at the content in this hyperlink: xiaopinggaiblog://xiappinggai/open. This is customized by me. Let’s first look at the writing method in the registration file of the application we want to open:
<activity android:name=".MainActivity" android:excludeFromRecents="true" android:label="@string/app_name" android:screenOrientation="portrait" > <intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter> <intent-filter> <action android:name="" /> <category android:name="" /> <category android:name="" /> <data android:pathPrefix="/xiappinggai/open" android:scheme="xiaopinggaiblog" /> </intent-filter> </activity>
What I am imitating here is to open the main interface of another program and see an intention filter below. Here is a < data/> tag, the contents in this tag:
<data android:pathPrefix="/xiappinggai/open"
android:scheme="xiaopinggaiblog" />
The PathPrefix property specifies only partial paths, which matches the initial part of the path in the Intent object.
The scheme attribute is used to set the scheme part of the URI. It is the most basic attribute set for a specified URI. At least one scheme attribute must be set to the filter, otherwise, other URI attributes will have no meaning.
If you need to configure this, you can perfectly open other APPs. At the same time, some browsers also support this function. If it cannot be opened during testing, you can consider changing the browser to test.
Next, let’s take a look at how to transfer data to which application? Actually, it's not difficult, just change the url: the details are as follows:
xiaopinggaiblog://xiappinggai/open?data=xiaopinggaiblog
What if you want to wear multiple parameters? In fact, it is also possible. You can use the & symbol to connect it, and write it like this:
xiaopinggaiblog://xiappinggai/open?data=xiaopinggaiblog&arga=value
So how to receive it in that application? In fact, it is also a matter of several lines of code. We write it like this in the Activity where we want to receive data:
Uri uridata = ().getData(); if (uridata!=null) { String mydata = ("data"); }
This way you can get the data by writing, but there is another problem. When the app you want to open is not installed, an error will occur when clicking to open the app, which will greatly affect the interactive experience. Therefore, we can do this:
(new WebViewClient(){ @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { ("file:///android_asset/"); (, "No this app", 0).show(); } });
This is OK, which is the operation performed when the web page fails to load. In addition to this prompt, we can also let him jump to the app download address and other series of operations he wants.
OK, all the code is here.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.