Preview:
Permissions Required:
1 <uses-permission android:name= " Com.android.launcher.permission.INSTALL_SHORTCUT " />
Configuration file: Androidmanifest.xml
1 <Activity2 Android:name= "Com.myself.news.activity.GuideActivity"3 Android:label= "@string/title_activity_guide" >4 <Intent-filter>5 <ActionAndroid:name= "Com.myself.news.ACTION_HOME" />6 7 <categoryAndroid:name= "Android.intent.category.DEFAULT" />8 </Intent-filter>9 </Activity>
The OnCreate method calls installshortcut() on the splash screen page of the app;
Code:
1 //Create a shortcut2 //Com.android.launcher.permission.INSTALL_SHORTCUT3 Private voidinstallshortcut () {4 //determine if a shortcut has been created5 Booleaniscreated = Sharedpreferencesutils.getboolean ( This,6Globalconstantsutils.pref_is_shortcut_intalled,false);7 //determine if you have already created a8 if(!iscreated) {9 //send a broadcastTenIntent Intent =NewIntent (); OneIntent.setaction ("Com.android.launcher.action.INSTALL_SHORTCUT"); A - //icons - //generate bitmap objects based on resource file ID the Intent.putextra (Intent.extra_shortcut_icon, Bitmapfactory - . Decoderesource (Getresources (), r.drawable.ic_launcher)); - //name -Intent.putextra (Intent.extra_shortcut_name, "mobile security Defender"); + - //Action +Intent actionintent =NewIntent (); A //Skip to Main page at actionintent.setaction (globalconstantsutils.action_home); - - Intent.putextra (intent.extra_shortcut_intent, actionintent); - Sendbroadcast (intent); - - //the tag has already created a shortcut and is no longer created inSharedpreferencesutils.setboolean ( This, -Globalconstantsutils.pref_is_shortcut_intalled,true); to } +}
Constant Tool class Globalconstantsutils:
1 public static final String pref_is_shortcut_intalled = "Is_shortcut_ Intalled "; // have you created a shortcut ?
1 public static final String action_home = "Com.myself.news.ACTION_HOME"; // action to jump to the main page
Mobile app to create desktop shortcuts