Я могу только понять, как запустить всплывающее сообщение функцию createshortcut, но не могу понять, откуда берется средство запуска пикселей и как его изменить / то есть запускать тост только после нажатия кнопки «Добавить на главную»?
Спасибо!
Код: Выделить всё
@RequiresApi(Build.VERSION_CODES.O)
private fun createShortcut(shortcutName: String, shortcutId: Int) {
val shortcutManager = getSystemService(ShortcutManager::class.java)
if (shortcutManager?.isRequestPinShortcutSupported == true) {
val shortcutIntent = Intent(this, MainActivity::class.java).apply {
action = Intent.ACTION_RUN
putExtra("route", "editNoteScreen")
putExtra("shortcutClicked", true)
putExtra("shortcutId", shortcutId)
}
val shortcutInfo = ShortcutInfo.Builder(this, shortcutId.toString())
.setShortLabel(shortcutName)
.setLongLabel(shortcutName)
.setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_icon))
.setIntent(shortcutIntent)
.build()
val pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(shortcutInfo)
val pendingIntentFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_IMMUTABLE
} else {
0
}
val successCallback = PendingIntent.getBroadcast(
this,
0,
pinnedShortcutCallbackIntent,
pendingIntentFlags
)
shortcutManager.requestPinShortcut(shortcutInfo, successCallback.intentSender)
}
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... in-android
Мобильная версия