欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android中創(chuàng)建快捷方式代碼實例

 更新時間:2015年04月24日 11:56:48   投稿:junjie  
這篇文章主要介紹了Android中創(chuàng)建快捷方式代碼實例,本文分為三個步驟實現(xiàn),并分別給出對應(yīng)實現(xiàn)代碼,需要的朋友可以參考下

1、添加權(quán)限(必須)

復(fù)制代碼 代碼如下:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

2、添加快捷鍵

復(fù)制代碼 代碼如下:

    public static void setupShortcut(Activity activity)
    {
        Intent shortcutIntent = new Intent(activity, MainActivity.class); //啟動首頁(launcher Activity)

        Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "hello");//快捷鍵名字可以任意,不過最好為app名稱
        Parcelable iconResource = Intent.ShortcutIconResource.fromContext(activity, R.drawable.ic_launcher);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
        intent.putExtra("duplicate", false);//不允許重復(fù)創(chuàng)建

        activity.sendBroadcast(intent);//發(fā)送廣播創(chuàng)建快捷鍵
    }

3、快捷鍵也可以指向非Launcher activity,只需要在AndroidManifest中對應(yīng)的Activity 中添加如下配置

復(fù)制代碼 代碼如下:

<intent-filter>
     <action android:name="android.intent.action.CREATE_SHORTCUT" />
<intent-filter>

例如可以將2 中的MainActivity 改為任意其他Activity,同時在AndroidManifest中對應(yīng)添加上述intent-filter就可以了。

相關(guān)文章

最新評論