<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "King. Demo"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<Activity Android: Name = ". mainactivity"
Android: Label = "@ string/app_name">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
<Action Android: Name = "android. Intent. Action. create_shortcut"/> // Add this sentence.
</Intent-filter>
</Activity>
</Application>
</Manifest>
Package king. Demo;
Import Android. App. activity;
Import Android. content. intent;
Import android.net. Uri;
Import Android. OS. Bundle;
Import Android. OS. parcelable;
Public class mainactivity extends activity {
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
// Intent of the shortcut to be added
Intent addshortcut;
// Determine whether to add shortcuts
If (getintent (). getaction (). Equals (intent. action_create_shortcut )){
Addshortcut = new intent ();
// Set the shortcut name
Addshortcut. putextra (intent. extra_shortcut_name, "Send email ");
// Create a shortcut icon
Parcelable icon = intent. javascuticonresource. fromcontext (this, R. drawable. Icon );
// Add a shortcut icon
Addshortcut. putextra (intent. extra_shortcut_icon_resource, icon );
// Build intent for quick execution
Intent mailto = new intent (intent. action_sendto, Uri. parse ("mailto: xxx@xxx.com "));
// Add a shortcut intent
Addshortcut. putextra (intent. extra_shortcut_intent, mailto );
// Normal, return, build a shortcut
Setresult (result_ OK, addmediacut );
}
Else {
Setresult (result_canceled );
}
// Close
Finish ();
}
}
Start the simulator, and you can find the added shortcut in the shortcuts list and add it to the desktop.