在创建快捷方式时,我会像"创建快捷方式"一样得到吐司,随后"快捷方式已存在".我已经设置了重复的意图,并没有创建任何重复.现在我怀疑了
如何检测快捷方式是否已存在.
如何禁用"快捷方式创建"和"快捷方式已存在"等Toast消息.我已经检查了显示Toast的LauncherModel(在com.android下)api,但像WhatsApp这样的应用程序不显示任何Toast.
创建快捷方式时,您可以像这样添加
addIntent.putExtra("duplicate",true);
(然后在创建时,创建重复的快捷方式,即使它存在)
ex.
public void createShortcut(String url,,String classname,String shortcutName , String type)
{
Intent shortcutIntent = new Intent();
shortcutIntent.setAction(Intent.ACTION_VIEW);
if(type.equalsIgnoreCase("web")) {
Uri uri = Uri.parse(url);
shortcutIntent.setData(uri);
}
else if (type.equalsIgnoreCase("app")) {
shortcutIntent.setClassName(url,classname);
}
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
addIntent.putExtra("duplicate", true);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, R.drawable.ic_launcher);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(addIntent);
// Toast mToast = Toast.makeText(this, "shortcut created", Toast.LENGTH_SHORT);
// mToast.show();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4499 次 |
| 最近记录: |