java - 如何在 Android 8 的主屏幕上创建快捷方式?

标签 java android android-8.0-oreo

我将在 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));

结果:

enter image description here

但结果我想自动创建快捷方式:

enter image description here

最佳答案

想通了。使用 ShortcutManager.requestPinShortcut。但请注意,该方法将打开一个对话框,询问用户是否将快捷方式添加到主屏幕。对我来说不幸的是,这个对话框是在其他 Activity 之后打开的,所以永远看不到!

关于java - 如何在 Android 8 的主屏幕上创建快捷方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47368018/

相关文章:

通过显式 TLS 进行 android ftp 文件传输

java - 无法以编程方式为 Android Oreo 上的通知 channel 更新声音

android - 如何每 5 分钟启动一次调度程序,在 Android 8(Oreo)中没有任何失败 - (尝试过的 Jobscheduler 最小限制是 15 分钟并且不可靠)

java - 使用变量初始化整数数组

java - 我如何将 bytearray 存储为 HashMap 中的值?

android - 尝试从 SQL 获取记录并比较 Android 中的字符串时出错

java - 从某些示例线程代码中获取 RuntimeException

java - 生产者消费者线程间通信

java - 异步任务,关闭alertdialog后进度对话框不会消失

java - 如何在 android oreo 中运行持续的后台服务?