In the Android operating system, an Activity containing the following attributes is displayed in the Application Manager (Launcher). Generally, this Activity corresponds to the main Activity of an application.
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. LAUNCHER"/>
In addition, if you want to add an app shortcut on the Home Screen of the device, you can press the app icon in the Launcher, the Android system automatically adds a shortcut for the application on the Home Screen, with the same name and icon as in Launcher.
In addition to the shortcut to the Application (main Activity), Android can define a shortcut to any Activity in the Application on Home Screen.
For example, you may frequently use a feature in your application. For example, you can query an address in a map. Normally, you need to start the main Activity first, it may take several menu selections or other methods to access this function. Users may feel inconvenient. This is to create a shortcut for this function on Home Screen, after you press this shortcut, you will directly enter this function interface, even if this Activity is not the main Activity.
Launcher Shortcuts describes how to create a shortcut on the Home Screen for a non-main Activity.
To implement this shortcut, you can perform the following steps:
1. add <action android: name = "android. intent. action. CREATE_SHORTCUT "/> to identify the Activity. You can add shortcuts to the Home Screen. Launcher Shortcuts uses the activity-alias, and activity-alias is the alias of Target, which is similar to Activity.
2. Add the code for adding shortcuts to the corresponding user. Generally, install shortcuts for the Activity in the onCreate method of the Activity:
[Java]
1. if (Intent. ACTION_CREATE_SHORTCUT.equals (action ))
2 .{
3. setupShortcut ();
4. finish ();
5. return;
6 .}
7.
8 ....
9. private void setupShortcut (){
10. // First, set up the specified cut intent.
11. // For this example, we simply create an intent that
12. // will bring us directly back to this activity.
13. // A more typical implementation wocould use
14. // data Uri in order to display a more specific result,
15. // or a custom action in order
16. // launch a specific operation.
17.
18. Intent shortcutIntent = new Intent (Intent. ACTION_MAIN );
19. shortcutIntent. setClassName (this, this. getClass (). getName ());
20. shortcutIntent. putExtra (EXTRA_KEY, "ApiDemos Provided This Shortcut ");
21.
22. // Then, set up the container intent (the response to the caller)
23.
24. Intent intent = new Intent ();
25. intent. putExtra (Intent. EXTRA_SHORTCUT_INTENT, shortcutIntent );
26. intent. putExtra (Intent. EXTRA_SHORTCUT_NAME, getString (R. string. shortcut_name ));
27. Parcelable iconResource = Intent. Reset cuticonresource. fromContext (
28. this, R. drawable. app_sample_code );
29. intent. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE, iconResource );
30.
31. // Now, return the result to the launcher
32.
33. setResult (RESULT_ OK, intent );
34 .}
If you want to create a Shortcut for an Activity, press the blank director in the Home Screen. Then, Android displays the list of desktop categories you can select and select Shortcut cut) android will list all android. intent. action. all applications of CREATE_SHORTCUT:
If ApiDemos is selected, Add to Home Screen starts LauncherShortcuts Activity, and the Intent action that sends the request is set to Intent. ACTION_CREATE_SHORTCUT, so you can use Intent in onCreate. ACTION_CREATE_SHORTCUT.equals (action) to determine whether the request is from Add to Home Screen or whether the user selects App-> Launcher Shorts. If it is from Add to Home Screen, Launcher Shortcuts creates a shortcut setupShortcut for this Activity and then exits.
Add to Home Screen after sending Intent requests (run startActivityForResult), it is expected to return a result from LauncherShortcuts, Which is why setupShortcut needs to return a result. The Intent of the created shortcut must define at least three parameters: SHORTCUT_INTENT (value: Intent), SHORTCUT_NAME (value: String), SHORTCUT_ICON (value: Bitmap), or SHORTCUT_ICON_RESOURCE (value: using cuticonresource ).
In this example, a shortcut is created for the current Activity (LauncherShortcuts). In actual applications, you can select a shortcut for another Activity or a list as needed.
In this example, create a Sample shortcut on Home Screen. After selecting this shortcut, go to Launcher Shortcuts without entering Launcher Shortcuts from the App.
Author: mapdigit