<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請(qǐng)您在轉(zhuǎn)載時(shí)注明出處http://www.tkk7.com/sxyx2008/謝謝合作!!!

    雪山飛鵠

    溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請(qǐng)您在轉(zhuǎn)載時(shí)注明出處http://www.tkk7.com/sxyx2008/謝謝合作!!!

    BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
      215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks
    ShortCutActivity
    package com.zhy.shortcut;

    import android.app.Activity;
    import android.content.ComponentName;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.content.SharedPreferences.Editor;
    import android.os.Bundle;
    import android.preference.PreferenceManager;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;

    public class ShortCutActivity extends Activity {

        
    private static final String CREATE_SHORTCUT_ACTION = "com.android.launcher.action.INSTALL_SHORTCUT";

        
    private static final String DROP_SHORTCUT_ACTION = "com.android.launcher.action.UNINSTALL_SHORTCUT";

        
    private static final String PREFERENCE_KEY_SHORTCUT_EXISTS = "IsShortCutExists";

        Button button;

        
    // 獲取默認(rèn)的SharedPreferences
        SharedPreferences sharedPreferences ;

        
    // 從SharedPreferences獲取是否存在快捷方式 若不存在返回false 程序第一次進(jìn)來肯定返回false
        boolean exists ;

        @Override
        
    public void onCreate(Bundle savedInstanceState) {
            
    super.onCreate(savedInstanceState);
            
            sharedPreferences 
    = PreferenceManager.getDefaultSharedPreferences(this);
            exists 
    = sharedPreferences.getBoolean(PREFERENCE_KEY_SHORTCUT_EXISTS, false);
            
    //創(chuàng)建桌面快捷方式
            
    //若第一次啟動(dòng)則創(chuàng)建,下次啟動(dòng)則不創(chuàng)建
            if (!exists) {
                setUpShortCut();
            }
            
            Intent intent
    =getIntent();
            String action
    =intent.getAction();
            
    //長(zhǎng)按桌面 創(chuàng)建快捷方式
            if(Intent.ACTION_CREATE_SHORTCUT.equals(action)){
                
                Intent shortCut
    =new Intent(Intent.ACTION_MAIN);
                shortCut.setClassName(
    thisthis.getClass().getName());
                
                Intent data
    =new Intent();
                
                data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(
    this, R.drawable.logo));
                data.putExtra(Intent.EXTRA_SHORTCUT_NAME, 
    "sina");
                data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortCut);
                data.putExtra(
    "duplicate"false);
                
                setResult(RESULT_OK, data);
                
                finish();
                
                
    return;
            }
            
            setContentView(R.layout.main);

            button 
    = (Button) findViewById(R.id.dropShortCut);

            button.setOnClickListener(
    new OnClickListener() {

                @Override
                
    public void onClick(View v) {
                    tearDownShortCut();
                }
            });
        }

        
        
        
        
    /**
         * 啟動(dòng)時(shí)創(chuàng)建桌面快捷方式
         
    */
        
    private void setUpShortCut() {

            Intent intent 
    = new Intent(CREATE_SHORTCUT_ACTION);

            
    // 設(shè)置快捷方式圖片
            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this, R.drawable.logo));

            
    // 設(shè)置快捷方式名稱
            intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "sina");

            
    // 設(shè)置是否允許重復(fù)創(chuàng)建快捷方式 false表示不允許
            intent.putExtra("duplicate"false);

            
            
            
    // 設(shè)置快捷方式要打開的intent
            
            
    // 第一種方法創(chuàng)建快捷方式要打開的目標(biāo)intent
            Intent targetIntent = new Intent();
            
    // 設(shè)置應(yīng)用程序卸載時(shí)同時(shí)也刪除桌面快捷方式
            targetIntent.setAction(Intent.ACTION_MAIN);
            targetIntent.addCategory(
    "android.intent.category.LAUNCHER");
            
            ComponentName componentName 
    = new ComponentName(getPackageName(), this.getClass().getName());
            targetIntent.setComponent(componentName);
            

            
    // 第二種方法創(chuàng)建快捷方式要打開的目標(biāo)intent
            /*
             * Intent
             * targetIntent=getPackageManager().getLaunchIntentForPackage(getPackageName
             * ());
             
    */
            intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);

            
    // 發(fā)送廣播
            sendBroadcast(intent);

            Editor editor 
    = sharedPreferences.edit();
            editor.putBoolean(PREFERENCE_KEY_SHORTCUT_EXISTS, 
    true);
            editor.commit();

        }

        
    /**
         * 刪除桌面快捷方式
         
    */
        @Deprecated
        
    private void tearDownShortCut() {

            Intent intent 
    = new Intent(DROP_SHORTCUT_ACTION);
            
    // 指定要?jiǎng)h除的shortcut名稱
            intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "sina");

            String appClass 
    = getPackageName() + "." + this.getLocalClassName();

            ComponentName component 
    = new ComponentName(getPackageName(), appClass);
            intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
    new Intent().setAction(Intent.ACTION_MAIN).setComponent(component));
            sendBroadcast(intent);

        }

        
        
        
        
        
        
        
        
    }
    AndroidManifest.xml
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package
    ="com.zhy.shortcut"
        android:versionCode
    ="1"
        android:versionName
    ="1.0" >

        
    <uses-sdk android:minSdkVersion="8" />
        
    <!-- 創(chuàng)建桌面快捷方式的權(quán)限 -->
        
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
        
    <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
        
    <application
            
    android:icon="@drawable/logo"
            android:label
    ="@string/app_name" >
            
    <activity
                
    android:label="@string/app_name"
                android:name
    =".ShortCutActivity" >
                
    <intent-filter >
                    
    <action android:name="android.intent.action.MAIN" />
                    
    <category android:name="android.intent.category.LAUNCHER" />
                
    </intent-filter>
            
    </activity>
            
    <activity-alias
                
    android:targetActivity=".ShortCutActivity"
                android:name
    =".AliasShortCutActivity" >
                
    <intent-filter >
                    
    <action android:name="android.intent.action.CREATE_SHORTCUT" />
                    
    <category android:name="android.intent.category.DEFAULT" />
                
    </intent-filter>
            
    </activity-alias>
        
    </application>

    </manifest>


    posted on 2011-12-13 14:24 雪山飛鵠 閱讀(1746) 評(píng)論(0)  編輯  收藏 所屬分類: android
    主站蜘蛛池模板: 精品国产综合成人亚洲区| 免费观看男人吊女人视频| 亚洲黄色在线观看| 久久精品国产亚洲Aⅴ香蕉| 成人免费午间影院在线观看| 久久99热精品免费观看牛牛| 国产精品福利片免费看| 亚洲A∨精品一区二区三区下载| 亚洲国产综合在线| 亚洲精品自产拍在线观看动漫| 国产成人综合亚洲亚洲国产第一页| 免费羞羞视频网站| 中文字幕无码不卡免费视频| 99久热只有精品视频免费观看17| 久久精品成人免费国产片小草| 美女黄频免费网站| 麻豆亚洲AV成人无码久久精品 | 精品久久久久久久免费加勒比| 亚洲人成免费网站| 久久国产免费观看精品3| 人妻免费一区二区三区最新| 一区二区三区免费精品视频| 免费精品国产自产拍在线观看| 香蕉视频亚洲一级| 国产成人va亚洲电影| 日韩亚洲人成网站| 国产av无码专区亚洲av毛片搜| 无码亚洲成a人在线观看| 亚洲av无码无线在线观看| 亚洲sm另类一区二区三区| 亚洲精品国产综合久久久久紧 | 免费无码又黄又爽又刺激| 91嫩草国产在线观看免费| 97热久久免费频精品99| 日韩免费一区二区三区在线播放| 免费99精品国产自在现线| 日韩吃奶摸下AA片免费观看| 成全高清视频免费观看| 免费观看男人免费桶女人视频| 日韩激情无码免费毛片| 又大又粗又爽a级毛片免费看|