The basic principles and implementation details of calling APP from the Web in Android

The basic principles and implementation details of calling APP from the Web in Android

Web-based APP is mainly based on the URL Scheme mechanism. URL Scheme is a protocol similar to http and https, which starts and transmits data to a specified APP through a specific link. This mechanism is supported on both iOS and Android platforms.

When you click a link containing a specific URL Scheme on a web page, the system will check whether the Scheme has been registered in an APP installed on the device. If a matching APP is found, the system will start the APP and pass the parameters in the link to the APP. The web page can call up the APP through the link and realize the data transfer.

Different platforms may have different support levels and restrictions for URL Scheme. For example, iOS platform has relatively good support for URL Scheme, but there are some restrictions in actual use, such as some applications may prohibit this way of invoking. On the Android platform, different application vendors also have different support for URL Scheme, and these differences need to be taken into account and adapted during implementation.

The implementation of Web-invoked APP also needs to consider some security issues, such as ensuring the uniqueness of the URL Scheme to avoid conflicts with other application schemes; verifying and filtering the transmitted data to prevent malicious attacks and data leakage.

Usage Examples

Define the scheme in AndroidManifest.xml. The scheme cannot be the same as the ones already used, such as http, https, ftp, sms, mailto, etc.

 <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <!-- web 唤起添加的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="reathin.scheme" android:host="reathin.host" /> </intent-filter> </activity>

Test Html page:

 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>Web唤起APP</title> </head> <body style="text-align: center"> <a href="my.scheme://reathin.host?name=Raysen¶m=我是参数" style="font-: 26px">点击唤起APP</a> </body> </html>

There are two parameters in the link, name and param, which can also pass some data when the APP is called up.

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = getIntent(); if (null != intent && null != intent.getData()) { Uri uri = intent.getData(); String name = uri.getQueryParameter("name"); String title = uri.getQueryParameter("param"); } }

In order to ensure that the Web can successfully invoke the APP, the corresponding link needs to be correctly configured in the Web page to ensure that the format and parameters of the link match the Scheme registered in the APP. Security is also an important factor to consider, and the security of the link needs to be ensured to prevent malicious attacks and data leakage.

<<:  The key to optimizing Bitmap memory usage: image resolution, folder storage and loading strategy

>>:  iOS 18 is about to be released, get to know the new features first

Recommend

Don’t use hand sanitizer and dryers in public toilets!

Do you often see these two things in public toile...

Give you the simplest project operation plan! That's all I can do to help!

During the operation process, we often have to wr...

There is a kind of romance in the universe, I am your companion star

Alien planetary system has a Jupiter world 99 tim...

This is how professional cat lovers suck cats...

According to a British study, 82% of girls find b...

Apple releases OS X Yosemite beta 5, continues to optimize Photos app

[[130368]] Apple today released the fifth beta of...

Amazon advertising, Amazon advertising placement

In the process of "pushing rankings" , ...

How to help offline education and training institutions to transform online?

The year 2020 has had a huge impact on most offli...

[Powerful] D3.js visualizes the number of SSH brute force attacks

This blog post is from 51CTO blogger Lao Xu_kevin...

Who will win the battle of words? ——Front-end and back-end passionate debate

Are you still worried about having nowhere to dis...