分享

Android生成快捷方式

 Dragon_chen 2016-09-16
避免多次生成快捷方式,存储一个boolean值判断是否已经生成快捷方式,生成快捷方式要添加权限
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
private void initShorCut() {
//给生成快捷方式的广播对应的意图添加action
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//添加快捷方式图标
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher));
//添加快捷方式名称
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"星空手机卫士");
//添加快捷方式意图,给开启的activity配置IntentFileter,
Intent jump = new Intent();
jump.setAction("android.intent.action.Home");
jump.addCategory("android.intent.category.DEFAULT");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,jump);

//发送广播隐式意图
sendBroadcast(intent);

SpUtil.writeBool(this,ConstValue.SHORT_CUT,true);
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多