我想让用户选择添加主屏幕快捷方式来启动应用程序(在第一次启动时提示他)。在主屏幕上创建快捷方式
我看到,例如WhatsApp的自动创建图标
我该怎么办呢?该应用是否需要额外的权限?由于
林,试图(但不工作)
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// Shortcut name
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "MyApp");
shortcut.putExtra("duplicate", false); // Just create once
// Setup current activity shoud be shortcut object
ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
// Set shortcut icon
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);
你有这个功能的工作? – Manikanta 2017-03-21 11:46:22