Android建立捷徑

來源:互聯網
上載者:User

Xml代碼 
<intent-filter> 
<action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 

在你的項目清單中看到如下代碼代表這個activity是本應用的啟動activity。系統會自動為建立捷徑。在你使用一些應用時它有時會讓你建立捷徑 比如 UC瀏覽器.這是怎麼做的呢?其實也很簡單。只需:
Java代碼 
/**
  * 這兩行代碼說明你想幹嘛
  */ 
Uri uri = Uri.parse("tel:0800000123");   
Intent myIntent = new Intent(Intent.ACTION_DIAL, uri); 
             
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); 
 
Parcelable icon = Intent.ShortcutIconResource. 
fromContext(this,R.drawable.beach); // 擷取快速鍵的表徵圖 
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 捷徑的表徵圖 
 
//shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, R.drawable.beach); //可以代替上面兩行代碼 
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "捷徑");// 捷徑的標題 
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);// 捷徑的動作 
 
sendBroadcast(shortcut);// 完了你還可以告訴系統你建立了個捷徑 


如果你還想在建立捷徑欄中添加一個你自己的條目 比如


 
 

你也只需在資訊清單檔中加入:(你要建立一個activity哦 NoneShortcut)
Xml代碼 
<activity android:name=".NoneShortcut" android:icon="@drawable/photo6" android:label="哈哈"> 
<intent-filter > 
<action android:name="android.intent.action.CREATE_SHORTCUT"/> 
</intent-filter> 
</activity> 

本文出自“sunney2012”
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.