There are several ways to create an application shortcut:
- On the launcher Application List, long press an application icon to create a shortcut to the desktop
- On the desktop, press the shortcut button in the pop-up box and select "shortcut"> "application"> "add a shortcut program ".
- Automatically created when the program is running
In the development of shortcuts, you must first determine whether a shortcut exists: Generally, add the oncreate method in the welcome interface of the program and the oncreate method of the activity that opens the first interface of the program.
If (! Hasshortcut ()){
Toast. maketext (mcontext, "saved shortcuts", Toast. length_long). Show ();
} Else {
Toast. maketext (mcontext, "no shortcut", Toast. length_long). Show ();
}
Creation method:
/**
* Determine whether shortcuts have been added to the desktop
*
* @ Param CX
* @ Param titlename
* Shortcut name
* @ Return
*/
Public Boolean hasshortcut (){
Boolean result = false;
// Obtain the name of the current application
String title = NULL;
Try {
Final packagemanager PM = getpackagemanager ();
Title = PM. getapplicationlabel (
PM. getapplicationinfo (getpackagename (),
Packagemanager. get_meta_data). tostring ();
} Catch (exception e ){
}
Final string uristr;
If (Android. OS. Build. version. sdk_int <8 ){
Uristr = "content: // com. Android. launcher. Settings/favorites? Required y = true ";
} Else {
Uristr = "content: // com. Android. launcher2.settings/favorites? Required y = true ";
}
Final URI content_uri = URI. parse (uristr );
Final cursor c = getcontentresolver (). Query (content_uri, null,
"Title =? ", New string [] {Title}, null );
If (C! = NULL & C. getcount ()> 0 ){
Result = true;
}
Return result;
}
Finally, add permissions:
<Uses-Permission Android: Name = "com. Android. launcher. Permission. read_settings"
OK! Judgment complete!