<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tangly.shortcut" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="7" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".StartActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="LoginActivity"/> </application> <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /></manifest>
Import Java. util. timer; import Java. util. timertask; import android. app. activity; import android. content. context; import android. content. intent; import android. content. sharedpreferences; import android. content. intent. export cuticonresource; import android. content. PM. activityinfo; import android. OS. bundle; import android. util. log; import android. view. window; import android. view. windowmanager;/*** @ author tanghl * Loading interface image **/public class startactivity extends activity {Private Static final string tag = "startactivity"; Private Static final string pai_short_cuts = "pai_short_cuts "; private Static final string iscreated = "iscreated"; Private Static final string action_install_shortcut = "com. android. launcher. action. install_shortcut "; static final string extra_shortcut_duplicate =" DUPLICATE "; @ override Publ IC void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setrequestedorientation (activityinfo. screen_orientation_nosensor); // disable the horizontal screen requestwindowfeature (window. feature_no_title); // hide the title getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen); // If (! Loadsharepref () {addshortcut (); try {setcontentview (R. layout. start_layout); Final timer = new timer (); timertask task = new timertask () {public void run () {intent = new intent (); intent. setclass (startactivity. this, app. class); startactivity (intent); timer. cancel (); startactivity. this. finish () ;}; // timer. schedule (task, 2000); timer. schedule (task, 1000);} catch (exception e) {log. E (Tag, E. tostring ();} //} else {// intent = getintent (); // intent. addflags (intent. flag_activity_new_task); // intent. addflags (intent. flag_activity_reset_task_if_needed); // intent. addflags (intent. flag_activity_launched_from_history); // startactivity (intent); //} // This. finish ();} private void addshortcut () {intent shortcut = new intent ("com. android. launcher. action. install_shortcut "); shortc Ut. putextra (intent. extra_shortcut_name, getstring (R. string. app_name); shortcut cut. putextra ("DUPLICATE", false); // repeated string action = "com. android. action. test "; intent = new intent (this, this. getclass (); // intent. setflags (intent. flag_activity_reset_task_if_needed); intent. addflags (intent. flag_activity_single_top); intent. setaction (action); cut. putextra (intent. extra_shortcut_intent, Intent); your cuticonresource iconres = intent. using cuticonresource. fromcontext (this, R. drawable. icon); // set the program icon shortcut cut. putextra (intent. extra_shortcut_icon_resource, iconres); sendbroadcast (shortcut cut); savesharepref ();}/** Save the ID */private void savesharepref () after creating a shortcut () {sharedpreferences share = getsharedpreferences (pai_short_cuts, context. mode_world_readable + context. mode_world_writeable); Share. edit (). putstring (iscreated, "yes "). commit ();}/** check whether shortcuts have been created before */private Boolean loadsharepref () {Boolean flag = false; sharedpreferences share = getsharedpreferences (cmd_short_cuts, context. mode_world_readable + context. mode_world_writeable); string result = share. getstring (iscreated, ""); If (null! = Result & "yes ". equals (result) {flag = true;} return flag;} @ override protected void onresume () {log. I (TAG, "startactivity is running ..... "); super. onresume ();}}
Download 1