Today I learned how to create and delete shortcuts. We can create shortcuts in two ways.
(1 ):Use an activity and click menu> Add> select shortcut> select created application on the home page.ProgramShortcutSee the following results:
The procedure is as follows:
①: Register the activity in the androidmanifset. xml file.
②: Add <action/>
Let's take a look at the core of the activity. Code : Public Class Shortcutsample extends activity {
@ Override
Protected Void Oncreate (bundle savedinstancestate ){
// Todo auto-generated method stub
Super. oncreate (savedinstancestate );
If (Getintent (). getaction (). Equals (
" Android. Intent. Action. create_shortcut " )){
Intent _ returnintent = New Intent ();
// Set the shortcut name
_ Returnintent. putextra (intent. extra_shortcut_name,
" Jiangqq shortcut " );
// Set shortcuts
_ Returnintent. putextra (intent. extra_shortcut_icon_resource,
Intent. Reset cuticonresource. fromcontext ( This ,
R. drawable. ic_launcher ));
Intent _ intent = New Intent (intent. action_call );
_ Intent. setdata (URI. parse ( " Tel: /// 10086 " ));
// After the shortcut is created, click the icon to go to the page for dialing.
_ Returnintent. putextra (intent. extra_shortcut_intent, New Intent (
This , Launcheractivity. Class ));
// Set the return value, which is generally OK,
Setresult (result_ OK, _ returnintent );
Finish ();
}
}
(2) Use sending broadcast to create a shortcut: In this demo, the function is as follows: click a button on the interface to generate a shortcut, click the shortcut to go To the dialing page;
The generation process is as follows:
1: The following permissions: <uses-Permission Android: Name = "com. Android. launcher. Permission. install_shortcut"/>
2: Add action to a new intent in activity:
_ Intent. setaction ("com. Android. launcher. Action. install_shortcut ");
3. Other core codes are as follows:
Intent _ returnintent = New Intent ();
// Sets the filter action for creating shortcuts.
_ 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 generated shortcut icon
_ Returnintent. putextra (intent. extra_shortcut_icon_resource,
Intent. Reset cuticonresource. fromcontext (
Launcheractivity. This , R. drawable. ic_launcher ));
Intent _ intent = New Intent (intent. action_call );
_ Intent. setdata (URI. parse ("Tel: // 5556 "));
_ Returnintent. putextra (intent. extra_shortcut_intent, _ intent );
// Send broadcast generation shortcut
Sendbroadcast (_ returnintent );
Launcheractivity. This . Finish ();
}
Of course, the above permission should be added to the call:
<Uses-Permission Android: Name = "android. Permission. call_phone"/>
If you want to uninstall shortcuts, you need to add permissions to the layout file.
<Uses-Permission Android: Name = "com. Android. launcher. Permission. uninstall_shortcut"/>
Then, import com. Android. launcher. Permission. uninstall_shortcut in intent.
The names of shortcuts to be deleted in other settings must be the same, and other codes are similar. You can also uninstall shortcuts by sending broadcasts .....
URL: http://greatverve.cnblogs.com/archive/2012/03/15/android-shutcut.html