Effect: on the desktop, press the shortcut icon and click "add shortcut ".
1: add
StartActivity (new Intent (ShortCutsActivity. this,
InstallMenuShortcut. class ));
2: Create InstallMenuShortcut
Package com. wop. ShortCuts;
Import android. app. Activity;
Import android. content. Context;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. OS. Parcelable;
Public class InstallMenuShortcut extends Activity {
Private Context mContext;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// The shortcut Intent to add
Intent addShortcut = new Intent ();
MContext = this;
AddShortcut. putExtra (Intent. EXTRA_SHORTCUT_NAME, mContext
. GetResources (). getString (R. string. app_name ));
Parcelable icon = Intent. Reset cuticonresource. fromContext (this,
R. drawable. ic_launcher); // icon of the ic_launcher shortcut
AddShortcut. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE, icon );
Intent ootStartIntent = new Intent (mContext, ShortCutsActivity. class); // The ShortCutsActivity shortcut must start the first Activity of the program
OotStartIntent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK );
AddShortcut. putExtra (Intent. EXTRA_SHORTCUT_INTENT, ootStartIntent );
SetResult (RESULT_ OK, addmediacut );
Finish ();
}
}
3: Add Manifest: www.2cto.com
<Activity
Android: label = "@ string/app_name"
Android: name = ". InstallMenuShortcut">
<Intent-filter>
<Action android: name = "android. intent. action. CREATE_SHORTCUT"/>
</Intent-filter>
</Activity>
It is taken from birds and birds without waiting for a day or night.