android 應用建立案頭捷徑

來源:互聯網
上載者:User

android的捷徑比較簡單,就是發一個系統的廣播,然後為捷徑設定Intent---package com.xikang.android.slimcoach.utils;/** * @author huiych * 建立捷徑 * @created 2013-02-21 * */import android.content.Intent;import android.os.Parcelable;import com.xikang.android.slimcoach.AppXiKang;import com.xikang.android.slimcoach.R;import com.xikang.android.slimcoach.ui.AppStart;public class ShortCutUtil { public static void initShortCut(){  Intent addShortCut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");  //不能重複建立捷徑  addShortCut.putExtra("duplicate", false);        String title = AppXiKang.getApp().getString(R.string.app_name);//名稱           Parcelable icon = Intent.ShortcutIconResource.fromContext(AppXiKang.getApp(), R.drawable.icon);//表徵圖          //點擊捷徑後操作Intent,捷徑建立後,再次啟動該程式             Intent intent = new Intent(AppXiKang.getApp(), AppStart.class);            //設定捷徑的標題             addShortCut.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);            //設定捷徑的表徵圖             addShortCut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);            //設定捷徑對應的Intent             addShortCut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);          //發送廣播添加捷徑             AppXiKang.getApp().sendBroadcast(addShortCut);  }}AppXiKange.getApp(),是擷取Activity對象。注意,要在資訊清單檔中設定許可權  <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>這樣在希望增加捷徑的時候,就可以給使用者一個alertdialog,提示,然後引用。就可以了。市場上也有很多應用是在應用安裝的時候直接建立捷徑。不過這樣的實現不是很友好。不建議使用。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.