Android创建快捷图标

来源:互联网 发布:linux查看当前用户 编辑:程序博客网 时间:2024/05/11 23:10
/** * 创建快捷图标 * 要包含三个重要信息 * 1.图标 * 2.名称 * 3.点击快捷图标后干什么 */public void installShortCut(){boolean shortCut = sp.getBoolean("shortCut", false);if(shortCut)//如果已经创建过快捷方式了,就不再创建return;//发送广播的意图,桌面创建快捷图标意图Intent intent = new Intent();intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "魔兽世界");//设置快捷方式的文字//设置快捷方式的图片intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));//桌面点击快捷图标后的意图Intent shortCutIntent = new Intent();//这种方式创建快捷方式后,把应用程序本身删除,快捷方式也会随之删除shortCutIntent.setAction("android.intent.action.MAIN");shortCutIntent.addCategory("android.intent.category.LAUNCHER");//启动能力的意图shortCutIntent.setClassName(getPackageName(), "com.xxc.mobilesafe.SplashActivity");//点击快捷方式后执行的意图//像这样创建快捷方式,不是指向程序入口的快捷方式,把应用程序本身给删除后,快捷方式并不会随之删除/*shortCutIntent.setAction("com.xxc.pikaxiong");shortCutIntent.addCategory(Intent.CATEGORY_DEFAULT);*/intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortCutIntent);//设置快捷方式点击后的意图sendBroadcast(intent);Editor editor = sp.edit();editor.putBoolean("shortCut", true);editor.commit();} 

0 0
原创粉丝点击