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

          雪山飛鵠

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

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks
          創(chuàng)建快捷方式的主Activity
          package com.zhy.weather;

          import android.app.Activity;
          import android.content.Intent;
          import android.os.Bundle;
          import android.os.Handler;
          import android.os.Parcelable;

          public class SplashActivity extends Activity {
              
              @Override
              
          protected void onCreate(Bundle savedInstanceState) {
                  
          super.onCreate(savedInstanceState);
                  
                  
          final Intent intent=getIntent();
                  
          final String action=intent.getAction();
                  
                  
          //設(shè)置允許創(chuàng)建快捷方式
                  if(Intent.ACTION_CREATE_SHORTCUT.equals(action)){
                      setupShortcut();
                      finish();
                      
          return;
                  }
                  
                  
                  setContentView(R.layout.splash);
                  
          new Handler().postDelayed(new Runnable() {
                      
                      @Override
                      
          public void run() {
                          SplashActivity.
          this.startActivity(new Intent(SplashActivity.this, MainActivity.class));
                          SplashActivity.
          this.finish();
                      }
                  }, 
          2000);
              }

              
          //創(chuàng)建快捷方式
              private void setupShortcut() {
                  
          //目標(biāo)Intent 打開快捷方式要啟動的那個intent
                  Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
                  shortcutIntent.setClassName(
          thisthis.getClass().getName());

                  
          // Then, set up the container intent (the response to the caller)

                  Intent intent 
          = new Intent();
                  intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
                  intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, 
          "小程序");
                  Parcelable iconResource 
          = Intent.ShortcutIconResource.fromContext(this,  R.drawable.app);
                  intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

                  
          // Now, return the result to the launcher

                  setResult(RESULT_OK, intent);
              }
              
              
              
          }

          AndroidManifest.xml
          <activity
                      
          android:name=".SplashActivity" >
                      
          <intent-filter >
                          
          <action android:name="android.intent.action.MAIN" />
                          
          <category android:name="android.intent.category.LAUNCHER" />
                      
          </intent-filter>
                  
          </activity>
                  
                  
          <!-- 創(chuàng)建桌面快捷方式 -->            
                  
          <activity-alias android:name=".CreateShortcuts"
                      android:targetActivity
          =".SplashActivity">
                      
          <intent-filter>
                          
          <action android:name="android.intent.action.CREATE_SHORTCUT" />
                          
          <category android:name="android.intent.category.DEFAULT" />
                      
          </intent-filter>
                  
          </activity-alias>   
          重點是注意activity-alias中的部分
          android:name 就是取個別名的意思
          android:targetActivity=".SplashActivity" 指定目標(biāo)Activity
          <action android:name="android.intent.action.CREATE_SHORTCUT" />指定該action才可以被android系統(tǒng)檢索到

          posted on 2011-12-13 14:03 雪山飛鵠 閱讀(1398) 評論(0)  編輯  收藏 所屬分類: android
          主站蜘蛛池模板: 廉江市| 方山县| 察隅县| 合阳县| 瓮安县| 五河县| 周宁县| 阳城县| 长葛市| 彭山县| 泊头市| 定襄县| 英德市| 拉孜县| 阳春市| 于都县| 宁德市| 高雄市| 普安县| 上蔡县| 大庆市| 泾川县| 治县。| 友谊县| 万源市| 萍乡市| 绥江县| 明溪县| 修文县| 嘉荫县| 日土县| 清水河县| 崇仁县| 盐边县| 孝义市| 营口市| 绥棱县| 靖宇县| 乌拉特中旗| 栾川县| 探索|