Android 8 Oreo でホームショートカットを作成する
Android 8 Oreo がリリースされて少し経ちました。
新機能をさっと眺めていたところホームショートカットの作成が、今までの方法ではできなくなると見かけました。
Android Oではcom.android.launcher.action.INSTALL_SHORTCUTが無効化された。かわりにrequestPinShortcutを使う。
そこで実際に確かめてみました。
emulator だけでの確認ですが、Oreo からは Broadcast による登録は不可能、requestPinShortcut() からは以下の UI から登録できました。
Android 8 以降
ShortcutManager#requestPinShortcut() を使います。以前に必要であった AndroidManifest.xml への permission を追加する必要はありません。
val manager = getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
val info = ShortcutInfo.Builder(this, "shortcut-id")
.setShortLabel("label")
.setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher_round))
.setIntent(intent)
.build()
manager.requestPinShortcut(info, null)
これだけですが、API >= 26 が必要です。
Android 7.1 以前
こちらも比較のために乗せておきます。
AndroidManifest.xml へ
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
を追加した上で、
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT")
...
sendBroadcast(intent)
Broadcast するだけです。Android 8 でこれを実行しても、残念ながら登録されません。エラーも表示されないため、知らないと意味がわからないかと思います。
Android 8 でホームショートカットを作成する皆様の参考になれば幸いです。
Author And Source
この問題について(Android 8 Oreo でホームショートカットを作成する), 我々は、より多くの情報をここで見つけました https://qiita.com/takeo-asai/items/dbed0fb62d6fb51a9730著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .