我想为用户提供添加主屏幕快捷方式来启动应用程序的选项(在第一次启动时提示他)。
我看到例如 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);
最佳答案
您是否在 list 文件中设置了 Activity Intent ?阅读此处:
关于java - 在主屏幕中创建快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8546885/