80,359
社区成员
发帖
与我相关
我的任务
分享
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); //不允许重复创建
//假设是图片类型
File file=new File("/sdcard/IMG/1.jpg");
Uri mUri = Uri.parse("file://"+file.getPath());
Intent it = new Intent(Intent.ACTION_VIEW);
it.setDataAndType(mUri, "image/*");//自己可以设置类型
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, it);
//快捷方式的图标
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(MainActivity.this, R.drawable.icon);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);