Android Desktop shortcuts

Source: Internet
Author: User

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"
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.