继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

android创建app快捷方式

陪伴而非守候
关注TA
已关注
手记 219
粉丝 61
获赞 284

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);
}

原文链接:http://www.apkbus.com/blog-917772-68582.html

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP