I previously wrote about how to create, delete, and determine shortcuts. However, I found that the methods used to determine shortcuts are not always effective. I checked them online and found that all the problems were solved after version 2.2. incorrect
Paste the original judgment method here
Java code
Private boolean hasShortCut (){
ContentResolver resolver = getContentResolver ();
Cursor cursor = resolver. query (Uri. parse ("content: // com. android. launcher. settings/favorites? Required y = true "), null," title =? ",
New String [] {getString (R. string. app_name)}, null );
If (cursor! = Null & cursor. moveToFirst ()){
Cursor. close ();
Return true;
}
Return false;
}
Later, I checked the configuration files in launcher 2.2 and 1.5.
The 1.5 is as follows:
Java code
<! -- Intent customized Ed used to install shortcuts from other applications -->
<Cycler
Android: name = ". InstallShortcutReceiver"
Android: permission = "com. lp. launcher. permission. INSTALL_SHORTCUT">
<Intent-filter>
<Action android: name = "com. lp. launcher. action. INSTALL_SHORTCUT"/>
</Intent-filter>
</Cycler>
<! -- Intent customized Ed used to uninstall shortcuts from other applications -->
<Cycler
Android: name = ". UninstallShortcutReceiver"
Android: permission = "com. lp. launcher. permission. UNINSTALL_SHORTCUT">
<Intent-filter>
<Action android: name = "com. lp. launcher. action. UNINSTALL_SHORTCUT"/>
</Intent-filter>
</Cycler>
<! -- The settings provider contains Home's data, like the workspace favorites -->
<Provider
Android: name = "LauncherProvider"
Android: authorities = "com. lp. launcher. settings"
Android: writePermission = "com. lp. launcher. permission. WRITE_SETTINGS"
Android: readPermission = "com. lp. launcher. permission. READ_SETTINGS"/>
The 2.2 is as follows:
Java code
<! -- Intent customized Ed used to install shortcuts from other applications -->
<Cycler
Android: name = "com. android. launcher2.InstallShortcutReceiver"
Android: permission = "com. android. launcher. permission. INSTALL_SHORTCUT">
<Intent-filter>
<Action android: name = "com. android. launcher. action. INSTALL_SHORTCUT"/>
</Intent-filter>
</Cycler>
<! -- Intent customized Ed used to uninstall shortcuts from other applications -->
<Cycler
Android: name = "com. android. launcher2.UninstallShortcutReceiver"
Android: permission = "com. android. launcher. permission. UNINSTALL_SHORTCUT">
<Intent-filter>
<Action android: name = "com. android. launcher. action. UNINSTALL_SHORTCUT"/>
</Intent-filter>
</Cycler>
<! -- The settings provider contains Home's data, like the workspace favorites -->
<Provider
Android: name = "com. android. launcher2.LauncherProvider"
Android: authorities = "com. android. launcher2.settings"
Android: writePermission = "com. android. launcher. permission. WRITE_SETTINGS"
Android: readPermission = "com. android. launcher. permission. READ_SETTINGS"/>
It can be seen that there is no change in the volume er used to create or delete shortcuts.
But the provider of the query has changed.
Java code
Android: authorities = "com. android. launcher. settings"
Java code
Android: authorities = "com. android. launcher2.settings"
Therefore, our method is invalid in Versions later than 2.2.
The modified code is as follows:
Java code
Public static boolean hasShortCut (Context context ){
String url = "";
System. out. println (getSystemVersion ());
If (getSystemVersion () <8 ){
Url = "content: // com. android. launcher. settings/favorites? Required y = true ";
} Else {
Url = "content: // com. android. launcher2.settings/favorites? Required y = true ";
}
ContentResolver resolver = context. getContentResolver ();
Cursor cursor = resolver. query (Uri. parse (url), null, "title =? ",
New String [] {context. getString (R. string. app_name)}, null );
If (cursor! = Null & cursor. moveToFirst ()){
Cursor. close ();
Return true;
}
Return false;
}
Private static int getSystemVersion (){
Return android. OS. Build. VERSION. SDK_INT;
}
Author "TryLoveCatch"