Abstract
This issue: How to hide the Android App Launcher icon on your desktop and support implicit protocols for launching your App.
demand
In a multi-app framework interaction, we would have one main App visible to the user, while the other sub-apps would only install and not display the startup icon on the desktop. For this scenario, it is necessary to hide the icon of the App, and ensure that the hidden App provides a portal to be launched.
Implementation scheme
1. Entry Activity configuration in general development
For an App with an initiator, the basic configuration of the entry Activity is as follows:
<activity
android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Copy the code
2. Hide the App’s desktop icon
<activity
android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<! To hide the desktop icon, note the configuration order of the three properties.
<! -- This data can be configured arbitrarily, preferably without host, just to hide the launcher icon -->
<data
android:host="hidelauncher.tyras.com"
android:scheme="tyras" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Copy the code
3. Enable the configuration implicitly
<activity
android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<! To hide the desktop icon, note the configuration order of the three properties.
<! -- This data can be configured arbitrarily, preferably without host, just to hide the launcher icon -->
<data
android:host="hidelauncher.tyras.com"
android:scheme="tyras" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<! - This is for implicit open, hidden desktop icon and implicit protocol configured separately, clearer. -->
<! DeepLink protocol, master protocol, common protocol for other applications. -->
<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="test.tyras.com"
android:path="/main"
android:scheme="tyras" />
</intent-filter>
</activity>
Copy the code
4. Validation tests
Following the configuration of the above 3 steps, you can realize the hidden icon of the App desktop, and support the implicit protocol to start the App.
The plan, not only in the use of the AS installation can run directly normal boot, but can use tyras://test.tryas.com/main implicit agreement to start.
Testing implicit protocols can be initiated using adb commands.
adb shell am start -d "tyras://test.tryas.com/main"
Copy the code
Detours in the implementation process
-
Some blog posts on the network, only half, not clear enough, and only part of the implicit startup configuration is not clear, there is a problem;
-
In my impression, the early system of Android can be realized by changing launcher to default, but it was found wrong during the test.
<category android:name="android.intent.category.LAUNCHER" />
Copy the code
Instead of
<category android:name="android.intent.category.DEFAULT" />
Copy the code
This plan won’t work.
-
In the normal configuration of starting an Activity, when adding the implicit protocol of data, do not pay attention to the order. When testing, it is found that the desktop icon can not be hidden when the data attribute is placed behind. Therefore, we should pay attention to the configuration order of the three attributes.
-
Although two intent-filters can be configured together, all attributes are required. This configuration is not recommended.
<activity
android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<! -- Hide desktop ICONS, support implicit protocol startup, pay attention to the configuration order of properties -->
<data
android:host="test.tyras.com"
android:path="/main"
android:scheme="tyras" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Copy the code
This configuration, also can use tyras://test.tryas.com/main privacy agreement to start, but must pay attention to the order and all the attributes a also cannot little.
Do not use this configuration mode because it is not convenient for later expansion and maintenance.