The Android native framework AppShortcuts used. Desktop shortcut button
There are two ways to implement the first one in the manifest configuration static way.
Use: Add the following meta-adta to the startup class
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
Create a shortcuts file in the xml folder :
Each shortcut is an item of the pop-up box. Up to 4 can be added (Google says 5)
icon: item icon
shortcutId: item id cannot be repeated. If repeated, only the first one will be displayed.
shortcutLongLabel: item text
intent: Click the target intent
targetClass: target class path
targetPackage: target application package name (it may not be your own application, as long as you can find the corresponding class after installation, you can jump)
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="@mipmap/del"
android:shortcutDisabledMessage="@string/static_message"
android:shortcutId="static1"
android:shortcutLongLabel="@string/static_long_label_1"
android:shortcutShortLabel="@string/static_short_label_1">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.example.myapplication.StaticTestActivity"
android:targetPackage="com.example.myapplication" />
</shortcut>
<shortcut
android:enabled="true"
android:icon="@mipmap/close"
android:shortcutDisabledMessage="@string/static_message"
android:shortcutId="static2"
android:shortcutLongLabel="@string/static_long_label_2"
android:shortcutShortLabel="@string/static_short_label_2">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.example.myapplication.StaticTestActivity"
android:targetPackage="com.example.myapplication" />
</shortcut>
</shortcuts>
Need to set the display content to the string.xml file. Otherwise, an error is reported: attribute resolution failed
<string name="static_message">asdf</string>
<string name="static_long_label_1">qwe</string>
<string name="static_short_label_1">qwe1</string>
<string name="static_long_label_2">qwe2</string>
<string name="static_short_label_2">qwe3</string>
The second is dynamically configured in the code.