preface

Wake up mode:

1, URL Schemes

2, the android appLink

3, chrome intent

DeepLink practices URL Schemes

A, need to be configured in the androidmanifest.xml file
<activity android:name=".ui.activity.SplashActivity" android:exported="true" android:screenOrientation="portrait" android:theme="@style/NormalSplash"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <! --DeepLink h5 --> <intent-filter> <! - ACTION_VIEW: support be retrieved - > < action android: name = "android. Intent. Action. VIEW" / > <! Implicit Intent -- CATEGORY_DEFAULT: response -- > < category android: name = "android. Intent. The category. The DEFAULT" / > <! - CATEGORY_BROWSABLE: can be aroused by Web browsers - > < category android: name = "android. Intent. Category. BROWSABLE" / > <! <data android:host="app.puxinwangxiao.com" Android :scheme="pxwxstudent" /> <! -- <data android:host="app.puxinwangxiao.com" android:scheme="pxwxstudent" android:pathPrefix="/pxwx"/> <data android:host="app.puxinwangxiao.com" android:scheme="pxwxstudent" android:path="/pxwx/user"/> --> </intent-filter> </activity>Copy the code

Note:

An App can be configured to support multiple activities that can be invoked

An Activity can be invoked by multiple urls

If an App is configured with multiple activities that can be invoked, their scheme and host are generally the same, and then they are differentiated by path, pathPrefix, etc

B. Parse URL data after being aroused

Parsing Uri data can be done in the Activity via getIntent().getData()

@Override public void onCreate(Bundle savesInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); Uri = getIntent().getData(); if (uri ! = null) {// scheme part String scheme=data.getScheme(); // host part String host= data.gethost (); // Access path String path=data.getPath(); / / parameter Set < String > paramKeySet = data. GetQueryParameterNames (); }}Copy the code
C. On the H5 page, use the following methods:
<! --1. Open with a TAB, click on the TAB to start --> <! - note the href format - > < a href = "pxwxstudent://app.puxinwangxiao.com" > open the android app < / a > <! Open - (2) through the iframe,. Set the iframe SRC will start -- > < iframe SRC = "pxwxstudent://app.puxinwangxiao.com" > < iframe > <! - 3. Directly through the window. The location of jump - > Windows. The location. The href = "pxwxstudent://app.puxinwangxiao.com";Copy the code
D. Invoke Intent mode in native App
Intent intent = new Intent();
intent.setData(Uri.parse("pxwxstudent://app.puxinwangxiao.com/"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Copy the code

DeepLink practices Android AppLink

A. Introduction to Android AppLink

Android M and above can use AppLinks to redirect users to specific pages of the App when they click on a link.

The premise is that the App has been installed and verified.

The biggest use of App Links is to avoid the selection of browser options when waking up the App from the page;

The premise is that the corresponding Scheme must be registered, so that the associated App can be opened directly.

Android App Links has the following benefits:

Security/particularity: Because Android App Links uses HTTP/HTTPS URL to authenticate the connection to the developer’s server, other applications cannot use our link

Seamless user experience: When the user does not install our application, due to the HTTP/HTTPS URL, it opens a web page where we can display the application description, etc., instead of displaying a 404 or other error page

Instant Apps support: You can use App Links to directly open an uninstalled Instant App

Support for Google Search or other browsers: Users can open our specific pages directly by clicking a URL in Google Search/Google Assistant/ mobile browser/screen Search

B. Android AppLink integration

Developer.android.com/studio/writ…

++ creates an intent filter++

Here we assume that the user is first by = = resource.puxinwangxiao.com/pxwx== to open our…

==Android Studio 2.3== App Links Assistant== to help developers quickly create the required ==intent filter== in == Androidmanifest.xml ==, There are several steps to using App Links Assistant:

Click on Tools > App Links Assistant in the Menu bar of Android Studio

Click Open URL Mapping Editor, then click + at the bottom of the dialog to add a new URL Mapping

In the Add URL Mapping dialog box that is displayed, enter Host, Path, and Activity, and click OK

Note: App Link supports multiple domain names

The following is automatically generated in the manifest file using the App Links Assistant:

<activity
            android:name=".ui.activity.SplashActivity"
            android:exported="true"
            android:screenOrientation="portrait"
            android:theme="@style/NormalSplash">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                
            </intent-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="http"
                    android:host="resource.puxinwangxiao.com"
                    android:path="/pxwx" />
            </intent-filter>
        </activity>
Copy the code

++ Check whether URL Mapping is correctly configured

The App Links Assistant provides a shortcut to check that URL Mapping is configured correctly, as follows:

Click Open URL Mapping Editor and enter URL in the Check URL Mapping dialog box. After entering a URL that can successfully match Acitivty, This URL maps to XXXXX (app) will be displayed at the bottom of the input box.

++ Handle App Links into the application scenario ++

Use App Links Assistant -> Select Activity to Select the Activity corresponding to the previously configured URL. Click Insert Code to Insert the Code in the onCreate method to get the URL from App Links. The generated code is as follows

// ATTENTION: This was auto-generated to handle app links.
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
Copy the code

++ Check whether assetlinks.json has been uploaded successfully ++

  • In order to in the application after the installation is successful, the system can automatically test whether the application has the right to use the corresponding domain name, system will to = = resource.puxinwangxiao.com/.well-known…

  • Through App Links Assistant -> Open Digital Asset Links File Generator -> Generate Digital Asset Links Json file, and then place the file in the correct domain address.

  • Through App Links Assistant -> Open Digital Asset Links File Generator -> Generate Digital Asset Links File -> Link and Verify can check whether the configuration file is correctly placed on the server. If the check is successful, the following image is displayed:

I hint here after test the Network error. Does not affect mainly resource.puxinwangxiao.com/.well-known…

If you want to connect your website to different applications

Websites can declare relationships with different apps in the same assetlinks.json file. This file lists the two statements below, the two statement declares the website and the link between the two application, this file is located in the app-pre.puxinwangxiao.com/.well-known…

[{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.pxwx.student", "sha256_cert_fingerprints": [" BD: EF: but D: 01: D0: wherefore discourage or E: wherefore discourage 3:18:32: E2:36: B9:35:1 plead B: 9 c: 7 D: 0 f: F0: B0: A9: BE: 91:18: CE: 27:1 A: D8:4 c "]}}, {" base ": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.pxwx.assistant", "sha256_cert_fingerprints": ["BD:EF:57:3D:01:D0:32:79:6E:32:73:18:32:E2:36:B9:35:1B:9C:7D:0F:F0:B0:A9:BE:91:18:CE:27:1A:D8:4C"] } }]Copy the code

Note the difference between path, pathPrefix, and pathPattern

For example: app-pre.puxinwangxiao.com/assistant/d…

  • Path is used to match the full path. Here, set path to /assistant/download.html to match.
  • PathPrefix is used to match the beginning of a path. In the case of the Uri above, setting pathPrefix to/Assistant will do the trick;
  • PathPattern uses expressions to match the entire path. Here we need to talk about matching symbols and escapes.

3, Implement Chrome Intent to launch the application from the browser

In many applications, we need to launch the application directly from the browser. Most of them use the first scheme method mentioned above. The problem is that if there is no application in the phone, the URL will jump to a wrong interface.

== Google has officially introduced an Android Intents method for app launch in Chrome, by setting SRC == in the iframe

intent:HOST/URI-path // Optional host
#Intent;
package=[string];
action=[string];
category=[string];
component=[string]; 
scheme=[string];
end;
Copy the code

The Mainfest file defines the activity to start

<activity
            android:name=".ui.activity.SplashActivity"
            android:exported="true"
            android:screenOrientation="portrait"
            android:theme="@style/NormalSplash">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-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:host="app.puxinwangxiao.com"
                    android:scheme="pxwxstudent" />
            </intent-filter>
        </activity>
Copy the code

Define an A tag as

<a href="intent://app.puxinwangxiao.com/#Intent; scheme=pxwxstudent; package=com.xxx.xxx; end">open Android App</a>Copy the code

Click the A TAB in the browser to launch the corresponding activity for the application.

If there is no corresponding application in the mobile phone, set the A label to avoid redirecting to the error page

<a href="intent://app.puxinwangxiao.com/#Intent; scheme=pxwxstudent; package=com.xxx.xxx; S.browser_fallback_url=https://www.puxinwangxiao.com; end">open Android App</a>Copy the code

If there is no corresponding application, the link will jump to the URL specified by == s.browser_fallback_URL ==.

4. Conclusion:

1. Compatibility with URL Scheme

URL Scheme only needs to register Scheme during the development of native App. When users click such links, the App will automatically wake up and jump to the specified page by virtue of the URL Router mechanism.

The URL Scheme is highly compatible, but has many limitations:

  • Browsers of different domestic manufacturers vary greatly, and this link is prone to error when the target App to be awakened is not installed.
  • There is currently no way to distinguish between registered schemes that are identical.
  • Jumping from UIWebView in other apps to target App is not supported.
  • Banned by some mainstream platforms, wechat, Weibo, QQ browser, mobile Baidu have been banned.

Because of these limitations, Android has released its second solution: App Links for Android.

2. App Links compatibility
  • App Links is not supported enough in China. Some Android browsers do not support jumping to App, but directly open the corresponding page on the browser.
  • When the system asks whether to open the corresponding App, if the user selects “Cancel” and “Remember this operation”, the user cannot jump to the App in the future.
3, Chrome Intent compatibility
  • Google’s optimization launched in Chrome;
  • Many third-party browsers will block Chrome intents to launch applications

These technologies are based on the system platform. After each iteration of the system version, there will be new changes in the configuration mode. Openinstall, a third-party platform in China, also provides special functions.