If you describe a project in a language that seems pale and powerless, I just let him see what he sees and what he sees is what he gets. As shown in:
1. The project diagram is as follows:
2. Add shrotcut as follows:
3. After the shortcut cut is added, home screen * (desktop) is as follows:
After adding a shortcut to the desktop, you can directly return to home (desktop) when you want to run this program, and click this shortcut to run this program.
The code is analyzed as follows:
(1) Permissions
If your application has a shortcut function, you must add the corresponding permissions to the manifest file, that is:
<Uses-Permission Android: Name = "com. Android. launcher. Permission. install_shortcut"/>
(2) action of the activity that creates the shortcut:
Add the activity of shortcut. The action must be Android. Intent. Action. create_shortcut, as shown below. You can also set it in the Code:
<Activity Android: Name = ". createshortcutactivity">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. create_shortcut"/>
<Category Android: Name = "android. Intent. Category. Default"/>
</Intent-filter>
</Activity>
(3) code for creating a shortcut:
Public static final string
Action_create_shortcut added in API Level 1
Activity action: Creates a shortcut.
Input: Nothing.
Output: an intent representing the specified cut. the intent must contain three extras: shortcut_intent (value: intent), shortcut_name (value: string), and shortcut_icon (value: Bitmap) or combine (value: Your cuticonresource ).
An intent represents a shortcut. This intent must contain three parameters: the intent type of the shortcut (the value is the intent type), the name of the shortcut (the value is a string type), and the shortcut icon (the type is a bitmap) or shortcut icon Resource (value: shortcut icon resource type ).
// Build the intent for the chosen Activity
// Set the intent of the shrorcut
Intent intent = new intent ();
Intent. setcomponent (New componentname (info. activityinfo. applicationinfo. packagename,
Info. activityinfo. Name ));
Intent result = new intent ();
Result. putextra (intent. extra_shortcut_intent, intent );
// Set the name of the shortcut
Result. putextra (intent. extra_shortcut_name, info. loadlabel (mpackagemanager ));
// Build the icon info for shorcut
Drawable = info. loadicon (mpackagemanager );
If (drawable instanceof bitmapdrawable ){
Bitmapdrawable BD = (bitmapdrawable) drawable;
Result. putextra (intent. extra_shortcut_icon, Bd. getbitmap ());
}
// Set the result
Setresult (result_ OK, result );
(4) Send a broadcast after the creation is successful:
// Boradcast an intent that tells the home screen to create a new shortcut
Result. setaction ("com. Android. launcher. Action. install_shortcut ");
Sendbroadcast (result );
The following http://code.google.com/p/apps-for-android/ for open-source apps-for-android