( i ) use the Send broadcast to create a shortcut : the demo example implements the following functions : in the interface there is a button, click the button to generate a shortcut, and then click on the shortcut to enter the phone call page ;
The build steps are as follows :
1: The following permissions : <uses-permission android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>
2: in Activity new one Intent join Action:
_intent.setaction ("Com.android.launcher.action.INSTALL_SHORTCUT");
3: The Other core code is as follows :
Intent _returnintent =NewIntent ();
// set Filter action to create shortcut
_returnintent
. Setaction ("Com.android.launcher.action.INSTALL_SHORTCUT");
// Set the name of the generated shortcut
_returnintent.putextra (Intent.extra_shortcut_name,
"Broad ShortCut");
// Set the icon for the generated shortcut
_returnintent.putextra (Intent.extra_shortcut_icon_resource,
Intent.ShortcutIconResource.fromContext (
Launcheractivity. This, R.drawable.ic_launcher));
Intent _intent =NewIntent (Intent.action_call);
_intent.setdata (Uri.parse ("tel://5556"));
_returnintent.putextra (Intent.extra_shortcut_intent, _intent);
// send broadcast generation shortcuts
Sendbroadcast (_returnintent);
Launcheractivity. This. Finish ();
}
of course, the above to join the call permission :
<uses-permission android:name= "Android.permission.CALL_PHONE"/>
If we want to uninstall the shortcut, we need to add the permission in the layout file
<uses-permission android:name= "Com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
Then the Com.android.launcher.permission.UNINSTALL_SHORTCUT is passed into the intent
( two ): use an Activity, and then click on the Home screen menu-> add Select Shortcut - Select the shortcut for the created application , see the following effect :
Create the steps below :
①: registering Activity in the androidmanifset.xml file
②: add <action/> below the intentfiler tab
Look at The core code in the Activity :
PublicclassShortcutsample extends Activity {
@Override
protectedvoidOnCreate (Bundle savedinstancestate) {
//TODO auto-generated method stub
Super.oncreate (savedinstancestate);
if(Getintent (). Getaction (). Equals (
"Android.intent.action.CREATE_SHORTCUT")) {
Intent _returnintent =NewIntent ();
// Set the name of the shortcut
_returnintent.putextra (Intent.extra_shortcut_name,
"Jiangqq ShortCut");
// set icon for shortcut
_returnintent.putextra (Intent.extra_shortcut_icon_resource,
Intent.ShortcutIconResource.fromContext ( This,
R.drawable.ic_launcher));
Intent _intent=NewIntent (Intent.action_call);
_intent.setdata (Uri.parse ("tel://10086"));
// when the shortcut is created, click the icon to jump to the page where you dialed the call
_returnintent.putextra (Intent.extra_shortcut_intent,NewIntent (
This, Launcheractivity.class));
// Set the return value , usually OK,
Setresult (RESULT_OK, _returnintent);
Finish ();
}
}
Creation of shortcuts for apps in Android