Android programming implementation click link to open app function example

This article describes the example of Android programming to click the link to open the app function. Share with you for your reference, as follows:

It is a common requirement to click the link to open the app in Android. For example, after e-commerce sends coupons to users, it often sends a text message: so and so coupons have been sent to your account. Click the XXX link to view them! At this time, when the user clicks the link, he will directly open the local app and enter the relevant pages.

Function realization:

1. Add an intent filter for the corresponding activity in the manifest:

2. Simulate sending a short message on the mobile phone, including a link http://mywebsite.com/openApp Generally, the mobile phone can automatically recognize the link. After clicking the link, the system will pop up a selection box as follows:

Click your app (androidtest) and the system will automatically open the testactivity page of the androidtest program.

3. However, the above practice is obviously not perfect, because users are likely to choose a browser to open this link! To solve this problem, you can modify the scheme attribute to user-defined, for example:

At this time, the corresponding link address is myapp://mywebsite.com/openApp Because only our own programs can recognize the myapp protocol on the local mobile phone, the app will be opened directly. However, there are still problems:

(1) If you put the link on the web page and want the user to click the link to open the app, there is no problem with the above practice. For example, add the following code to the web page:

(2) However, if you put the link in a text message, it won't work. Because the short message program of the myapp protocol system can't recognize it, it won't be marked as a link style, that is, users can't click directly.

The solution to this problem is to use the web page redirection function, such as sending links in SMS: http://abc.com/openApp , and then add a redirect to the page:

After clicking in the message, the user will open the link using the browser, and then automatically open his own app.

4. Finally, you can get the parameters passed by the link URL in testactivity:

PS: for the properties and functions related to the androidmanifest.xml file, please refer to the online tools of this website:

Description of Android manifest functions and permissions: http://tools.jb51.net/table/AndroidManifest

For more Android related content, readers who are interested can view the topics on this site: summary of Android basic component usage, summary of Android view skills, summary of Android layout skills, summary of Android resource operation skills, summary of Android file operation skills, introduction and advanced tutorial of Android development Activity operation skills summary of Android programming and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>