Summary of APP wake-up methods

For some relatively large projects, there may be other APP entrances in the business. Generally divided into two types: 1. The SDK of a friend is embedded in the project (the SDK that integrates part of the business) 2. The SDK of the friend who is awakened (mainly the installed app), let’s talk about waking up today.

  1. Use Intent to wake up by package name and type:

  The evoked APP class is configured in manifest.xml:

<activity android:name=".MyTestActivity1"
    android:exported="true"
    >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

</activity>

 Wake-up start: com.example.myapplication1 is the package name, com.example.myapplication1.MyTestActivity1 is the package name. Class name

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example.myapplication1",
        "com.example.myapplication1.MyTestActivity1"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

 

2. Use Uri to wake up via intent:

<activity android:name=".TestActivity3"
    android:exported="true"
    >
    <intent-filter>
        <action android:name="test.action" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:host="test.uri.activity"
            android:scheme="app" />
    </intent-filter>
</activity>

start up:

Uri uri = Uri.parse("app://test.uri.activity?id=1");
Intent intent2 = new Intent("test.action");
intent2.setData(uri);
startActivity(intent2);

The awakened page gets the parameters passed by Uri:

if (null != intent) {
    Uri uri = intent.getData();
    if (uri == null) {
        return;
    }
    String TAG = "TAG";
    if (uri != null) {
        // 完整的url信息
        String url = uri.toString();
        Log.e(TAG, "url: " + url);
        // scheme部分
        String scheme = uri.getScheme();
        Log.e(TAG, "scheme: " + scheme);
        // host部分
        String host = uri.getHost();
        Log.e(TAG, "host: " + host);
        String data = uri.getQueryParameter("id");
        Toast.makeText(this, data, Toast.LENGTH_SHORT).show();
    }

}

3. Wake up from H5 web browser:

1. First write a small web project, just have a web page as shown in the figure below, and deploy it to tomcat:

Open this link on the browser is:

We must open this link in the browser of the mobile phone, and it looks like this

2. Configuration:

<activity android:name=".TestActivity4"
    android:exported="true"
    >
    <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="app" android:host="test.my.app" android:pathPrefix="/path" />
    </intent-filter>
</activity>

After the configuration is complete, click ""click me..."" on the page loaded by the mobile browser to wake up.

Corresponding to this page to obtain parameters:

String TAG="TAG"; 
        Uri uri = getIntent().getData(); 
        if (uri != null) { 
            // Complete url information 
            String url = uri.toString(); 
            Log.e(TAG, "url: "+ url); 
            // scheme part 
            String scheme = uri.getScheme(); 
            Log.e(TAG, "scheme:" + scheme); 
            // host part 
            String host = uri.getHost(); 
            Log.e(TAG , "host: "+ host); 
            //port part 
// int port = uri.getPort(); 
// Log.e(TAG, "host:" + port); 
            // Access Road King 
            String path = uri. getPath(); 
            Log.e(TAG, "path:" + path);
            List<String> pathSegments = uri.getPathSegments(); 
            // Query part 
            String query = uri.getQuery(); 
            Log.e(TAG, "query: "+ query); 
            //Get the specified parameter value 
            String goodsId = uri. getQueryParameter("query1"); 
            Log.e(TAG, "query1: "+ goodsId)

Note: 1. scheme, host, path are all lowercase

            2.scheme do not use http or https

Guess you like

Origin blog.csdn.net/lk2021991/article/details/96006211