Shortcut tool Classes

Source: Internet
Author: User

Required Permissions:

<android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>  <android:name= "Com.android.launcher.permission.UNINSTALL_SHORTCUT" /> <  android:name= "Com.android.launcher.permission.READ_SETTINGS"/>

/*** Shortcut Tool class*/ Public classShortcututils {/*** Add desktop shortcuts for current app *@paramCX*/     Public Static voidaddshortcut (Context cx) {Intent shortcut=NewIntent ("Com.android.launcher.action.INSTALL_SHORTCUT"); Intent shortcutintent=Cx.getpackagemanager (). Getlaunchintentforpackage (Cx.getpackagename ());        Shortcut.putextra (Intent.extra_shortcut_intent, shortcutintent); //get the current app nameString title =NULL; Try {            FinalPackagemanager pm =Cx.getpackagemanager (); Title=Pm.getapplicationlabel (Pm.getapplicationinfo (Cx.getpackagename (), Pack        Agemanager.get_meta_data). toString (); } Catch(Exception e) {}//Shortcut NameShortcut.putextra (Intent.extra_shortcut_name, title); //duplicate creation is not allowed (not necessarily valid)Shortcut.putextra ("Duplicate",false); //icon for shortcutParcelable Iconresource =Intent.ShortcutIconResource.fromContext (CX, R.drawable.ic_launcher);        Shortcut.putextra (Intent.extra_shortcut_icon_resource, Iconresource);    Cx.sendbroadcast (shortcut); }    /*** Delete the desktop shortcut for the current app *@paramCX*/     Public Static voiddelshortcut (Context cx) {Intent shortcut=NewIntent ("Com.android.launcher.action.UNINSTALL_SHORTCUT"); //get the current app nameString title =NULL; Try {            FinalPackagemanager pm =Cx.getpackagemanager (); Title=Pm.getapplicationlabel (Pm.getapplicationinfo (Cx.getpackagename (), Pack        Agemanager.get_meta_data). toString (); } Catch(Exception e) {}//Shortcut NameShortcut.putextra (Intent.extra_shortcut_name, title); Intent shortcutintent=Cx.getpackagemanager (). Getlaunchintentforpackage (Cx.getpackagename ());        Shortcut.putextra (Intent.extra_shortcut_intent, shortcutintent);    Cx.sendbroadcast (shortcut); }    /*** Determine if the current app has desktop shortcuts on the desktop *@paramCX*/     Public Static Booleanhasshortcut (Context cx) {Booleanresult =false; String title=NULL; Try {            FinalPackagemanager pm =Cx.getpackagemanager (); Title=Pm.getapplicationlabel (Pm.getapplicationinfo (Cx.getpackagename (), Pack        Agemanager.get_meta_data). toString (); } Catch(Exception e) {}FinalString Uristr; if(Android.os.Build.VERSION.SDK_INT < 8) {Uristr= "Content://com.android.launcher.settings/favorites?notify=true"; } Else{uristr= "Content://com.android.launcher2.settings/favorites?notify=true"; }        FinalUri Content_uri =Uri.parse (URISTR); FinalCursor C = cx.getcontentresolver (). Query (Content_uri,NULL,                "Title=?",NewString[] {title},NULL); if(c! =NULL&& c.getcount () > 0) {result=true; }        returnresult; }}

Shortcut tool Classes

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.