当前位置: 移动技术网 > 移动技术>移动开发>Android > android编程实现为程序创建快捷方式的方法

android编程实现为程序创建快捷方式的方法

2019年07月24日  | 移动技术网移动技术  | 我要评论

本文实例讲述了android编程实现为程序创建快捷方式的方法。分享给大家供大家参考,具体如下:

/**
* 为程序创建桌面快捷方式
*/
private void addshortcut(){
intent shortcut = new intent("com.android.launcher.action.install_shortcut");
//快捷方式的名称
shortcut.putextra(intent.extra_shortcut_name, getstring(r.string.app_name));
shortcut.putextra("duplicate", false); //不允许重复创建
//指定当前的activity为快捷方式启动的对象: 如
//com.everest.video.videoplayer
//注意: componentname的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序
componentname comp = new componentname(this.getpackagename(), "."+this.getlocalclassname());
shortcut.putextra(intent.extra_shortcut_intent, new intent(intent.action_main).setcomponent(comp));
//快捷方式的图标
shortcuticonresource iconres = intent.shortcuticonresource.fromcontext(this, r.drawable.icon);
shortcut.putextra(intent.extra_shortcut_icon_resource, iconres);
sendbroadcast(shortcut);
}

希望本文所述对大家android程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网