Android Hide App icon, use shortcut to do boot entry, implement pseudo dynamic change icon

Source: Internet
Author: User

Today met very speechless very pit demand, said to be installed in the application according to the parameters of the different dynamic generation of desktop icons, which is basically impossible in Android, there is a stackoverflow on the following sentence:

You cannot change the application icon (or the Android manifest, or any other application resource for that matter) once Y Our APK is compiled. The only-to-do-is-to-re-compiling and pushing an update-to-the-market. In other words, the application is packaged well and there is almost no way to change its icon, let alone the dynamic generation!

This problem today is also plagued me for a long time, really can not find the practice, then someone prompted the next can use a shortcut, slowly try to disguise the pain of the need to achieve the needs.

First look at how to create shortcuts for your app, delete shortcuts, and determine if a shortcut already exists.

  

1 //New Shortcuts2     Private voidShortcutadd (String name,intNumber ) {3             //set the activity (main entrance) to open after a shortcut is clicked4Intent shortcutintent =NewIntent (Getapplicationcontext (), mainactivity.class);5 shortcutintent.setaction (constant.action_play);6 7             //this creates a Numbe bitmap, and you can set the chart you want.8Bitmap Bitmap =Bitmapfactory.decoderesource (Getresources (), r.drawable.ic_launcher);9Paint paint =NewPaint ();TenPaint.setcolor (0xff808080);//Gray One paint.settextalign (Paint.Align.CENTER); APaint.settextsize (50); -             NewCanvas (bitmap). DrawText ("" +number, 50, 50, paint); -  the             //Set Shortcut -Intent addintent =NewIntent (); - Addintent.putextra (intent.extra_shortcut_intent, shortcutintent); - Addintent.putextra (Intent.extra_shortcut_name, NAME); + Addintent.putextra (Intent.extra_shortcut_icon, bitmap); -  +             //Create a shortcut AAddintent.setaction ("Com.android.launcher.action.INSTALL_SHORTCUT"); at Getapplicationcontext (). Sendbroadcast (addintent); -         } -         //Delete Shortcut -         Private voidShortcutdel (String name) { -             //Intent to was send, when shortcut was pressed by user ("launched") -Intent shortcutintent =NewIntent (Getapplicationcontext (), mainactivity.class); in shortcutintent.setaction (constant.action_play); -  to             //decorate the shortcut +Intent delintent =NewIntent (); - Delintent.putextra (intent.extra_shortcut_intent, shortcutintent); the Delintent.putextra (Intent.extra_shortcut_name, NAME); *              $             //Inform Launcher to remove shortcutPanax Notoginseng             //Delete Shortcut -Delintent.setaction ("Com.android.launcher.action.UNINSTALL_SHORTCUT"); the Getapplicationcontext (). Sendbroadcast (delintent); +         } A          the         //determine if a shortcut exists +          Public Booleanisaddshortcut () { -  $             FinalContentresolver CR = This. Getcontentresolver (); $  -             intVersionlevel =Android.os.Build.VERSION.SDK_INT; -String authority = "Com.android.launcher2.settings"; the              -             //more than 2.2 of the system's file names are not the sameWuyi             if(Versionlevel >= 8) { theauthority = "Com.android.launcher2.settings"; -}Else { Wuauthority = "Com.android.launcher.settings"; -             } About  $             FinalUri Content_uri = Uri.parse ("content://" +Authority -+ "/favorites?notify=true"); -Cursor C =cr.query (Content_uri, -                     NewString[] {"title", "Iconresource"}, "Title=?", A                     NewString[] {getString (r.string.app_name)},NULL); +  the             if(c! =NULL&& c.getcount () > 0) { -                 return true; $             } the             return false; the}

Do not forget to add the appropriate permission settings:

<android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>   <android:name= "Com.android.launcher.permission.UNINSTALL_ SHORTCUT "/>

The above is how to create for the app, delete the app shortcut, but the need is to dynamically set the icon, just add the shortcut, the original app icon is still in, we can also set the app icon does not display.

This is how to hide the app icon

As long as it is set under the <intent-filter> node in the manifest file

<data android:host= "mainactivity" android:scheme= "Com.android.example"/> can be.
 <ActivityAndroid:name= "Com.longtime.ajy.MainActivity"android:screenorientation= "Portrait"Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <!--data android:host= "mainactivity" android:scheme= "com.android.example"/ -                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>

about why this setting does not show icons: http://blog.csdn.net/xiazdong/article/details/7764865 here is a good description, interested to see.

Android Hide App icon, use shortcut to do boot entry, implement pseudo dynamic change icon

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.