我将在 Android 8 的主屏幕上创建快捷方式并使用 ShortcutManager
它在上下文菜单中创建快捷方式,用户应该在主屏幕上手动拖动快捷方式,而在较低的 Android 8 中自动在主屏幕上创建
我的代码是:
ShortcutManager sM = (ShortcutManager) getSystemService(SHORTCUT_SERVICE);
Intent intent1 = new Intent(getApplicationContext(), MasterActivity.class);
intent1.setAction(Intent.ACTION_VIEW);
ShortcutInfo shortcut1 = new ShortcutInfo.Builder(this, "shortcut1")
.setIntent(intent1)
.setLongLabel("Ayande")
.setShortLabel("This is the Ayandeh")
.setDisabledMessage("Login to open this")
.setIcon(Icon.createWithResource(this, R.drawable.ayandeh))
.build();
sM.addDynamicShortcuts(Arrays.asList(shortcut1));
结果:
但结果我想自动创建快捷方式:
最佳答案
想通了。使用 ShortcutManager.requestPinShortcut。但请注意,该方法将打开一个对话框,询问用户是否将快捷方式添加到主屏幕。对我来说不幸的是,这个对话框是在其他 Activity 之后打开的,所以永远看不到!
关于java - 如何在 Android 8 的主屏幕上创建快捷方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47368018/