实现Android桌面的App快捷方式

本文描述的是,在App开发过程中,该如何实现App在Anroid桌面上生成App的快捷方式。主要分为两个步骤:

一,在AndroidManifest.xml中声明相关权限:

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

二,在代码实现如下:

    Intent addIntent=new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    Parcelable icon=Intent.ShortcutIconResource.fromContext(MainActivity.this,R.drawable.sms);
    Intent myIntent=new Intent(MainActivity.this,MainActivity.class);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,myIntent);
    sendBroadcast(addIntent);

如此般,你便在应用中实现了生成App的快捷方式到Android桌面。

 

人生苦短,快乐并不是每一天的,珍惜当下。

posted @ 2015-11-12 17:43  Francis.Liang  阅读(1293)  评论(0编辑  收藏  举报