android创建app快捷方式

来源:互联网 发布:php教程做表格 编辑:程序博客网 时间:2024/06/16 20:13

1.在清单文件中添加权限

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

2.在清单文件的activity节点添加意图过滤器(点击快捷方式打开的activity)

<activity android:name=".activity.MainActivity">    <intent-filter>        <action android:name="com.jaychan.demo.MAIN"/>        <category android:name="android.intent.category.DEFAULT"/>    </intent-filter></activity> 

其中的action节点中的name属性自己定义,一般都是app的包名然后加点东西就行了

3.代码

//创建快捷方式private void installShortcut() {        Intent intent = new Intent();        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "我的app");// 快解方式名称        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory                .decodeResource(getResources(), R.mipmap.app_icon));// 快解方式图标        Intent actionIntent = new Intent();        actionIntent.setAction("com.jaychan.demo.MAIN");  //需要和清单文件定义的那个action一致        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);        sendBroadcast(intent);}
原创粉丝点击