Я отчаянно пытался создать собственное уведомление для запуска, когда получаю сообщение. Я пытаюсь создать уведомление наподобие входящего вызова в WhatsApp, которое дает мне возможность отвечать и игнорировать, когда телефон не заблокирован, и отображать полноэкранное действие, когда заблокировано. Я также пытался замолчать мое уведомление; Единственный способ, которым мне удалось это сделать, это добавить файл без вывода сообщений. Кажется, ничего не работает, он не будет вибрировать, когда приложение не на переднем плане, и не будет отображаться на экране блокировки, когда телефон заблокирован. Это мой манифест:
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
это мой onrecive:
override fun onMessageReceived(p0: RemoteMessage) {
if (p0.data.isNotEmpty())
sendNotification()
}
и это мое удовольствие от уведомлений:
private fun sendNotification() {
val notificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val NOTIFICATION_CHANNEL_ID = "MY_CHANNEL"
val emptySound=Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE+"://"+packageName+"/"+R.raw.one_sec_silence)
val fullScreenIntent = Intent(this, AnswerActivity::class.java)
val fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT)
@RequiresApi(Build.VERSION_CODES.O)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationChannel = NotificationChannel(
NOTIFICATION_CHANNEL_ID,
"desc",
NotificationManager.IMPORTANCE_HIGH
)
val audioAttributes: AudioAttributes =
AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setLegacyStreamType(AudioManager.STREAM_NOTIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT).build()
notificationChannel.description = "desc"
notificationChannel.vibrationPattern = longArrayOf(0, 1000, 500, 1000)
notificationChannel.enableVibration(true)
notificationChannel.setSound(emptySound,audioAttributes)
notificationManager.createNotificationChannel(notificationChannel)
}
val notificationBuilder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
notificationBuilder
.setCategory(NotificationCompat.CATEGORY_CALL)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setVibrate(longArrayOf(0, 1000, 500, 1000))
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.star_big_off)
.setContentTitle("MYapp")
.setContentText("content")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setSound(emptySound)
.setFullScreenIntent(fullScreenPendingIntent,true)
.setOnlyAlertOnce(false)
notificationManager.notify(1, notificationBuilder.build())
}
}
Я был бы очень признателен за помощь, спасибо
РЕДАКТИРОВАТЬ: Я тестировал на android 10, я понимаю, что может быть другой способ достижения моей цели на android 1o