项目需要,创建一个动作的快捷方式到桌面,点击快捷方式作出相应的接口请求。
//创建一个添加快捷方式的Intent Intent addSC=new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); //快捷键的标题 String title= sceneInfo.getName(); //快捷键的图标 Parcelable icon=Intent.ShortcutIconResource.fromContext( mContext, R.drawable.scene_bright_0); //创建单击快捷键启动本程序的Intent Intent launcherIntent=new Intent(mContext.getApplicationContext(), HomePageActivity1.class); //传参到指定界面,通过标识和具体数据执行 launcherIntent.putExtra("scene_id",sceneInfo.getSceneID()); launcherIntent.putExtra("scene_name",sceneInfo.getName()); launcherIntent.putExtra("scene_icon",sceneInfo.getIcon()); launcherIntent.putExtra("is_fast",true); //设置快捷键的标题 addSC.putExtra(Intent.EXTRA_SHORTCUT_NAME, title); //设置快捷键的图标 addSC.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); //设置单击此快捷键启动的程序 addSC.putExtra(Intent.EXTRA_SHORTCUT_INTENT,launcherIntent); //向系统发送添加快捷键的广播 mContext.sendBroadcast(addSC); Toast.makeText(mContext.getApplicationContext(),"添加成功",Toast.LENGTH_SHORT).show();
大部分都是网上查询的资料,红色的标识是因为我需要拿到参数发送数据请求自己探索的。
记录一下。
