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 (isInstallShortcut ()){
Toast. makeText (mContext, "saved shortcuts", Toast. LENGTH_LONG). show ();
} Else {
Toast. makeText (mContext, "no shortcut", Toast. LENGTH_LONG). show ();
}
Creation method:
/**
* Determine whether there are shortcuts
*
* @ Return
*/
Private boolean isInstallShortcut (){
// TODO Auto-generated method stub
Boolean isInstallShortcut = false;
Final ContentResolver cr = mContext. getContentResolver ();
Final String AUTHORITY = "com. android. launcher. settings ";
Final Uri CONTENT_URI = Uri. parse ("content: //" + AUTHORITY
+ "/Favorites? Optional Y = true ");
Cursor c = cr. query (
CONTENT_URI,
New String [] {"title", "iconResource "},
"Title =? ",
New String [] {mContext. getResources (). getString (
R. string. app_name)}, null );
If (c! = Null & c. getCount ()> 0 ){
IsInstallShortcut = true;
}
Return isInstallShortcut;
}
Www.2cto.com
Finally, add permissions:
<Uses-permission android: name = "com. android. launcher. permission. READ_SETTINGS"
OK! Judgment complete!
It is taken from birds and birds without waiting for a day or night.