Мой канал уведомления не создаетсяAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Мой канал уведомления не создается

Сообщение Anonymous »

Всякий раз, когда я отправляю уведомление через FCM. < /p>
оно говорит, что оно будет использовать по умолчанию из манифеста или приложения Android, я также упомянул свой канал в манифесте как дефолт.
просто говорит, что канал не создан приложением.W/FirebaseMessaging: Notification Channel requested (message_notification) has not been created by the app. Manifest configuration, or default, value will be used.
< /code>
Это моя функция OnmessageReceived. < /p>
override fun onMessageReceived(p0: RemoteMessage) {
super.onMessageReceived(p0)
sound=Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE+":/ /"+applicationContext.packageName+"/"+R.raw.alert)
Log.d("notofiction Nul", sound.toString())

if(p0.notification!=null){

val title = p0.data["title"]
val message = p0.data["body"]
Log.d("notottg",title+message)
buildNotificationChannel()
if(buildNotificationChannel()){
generateNotification(title!!,message!!)
}

}
else{
val title = p0.data["title"]
val message = p0.data["body"]
Log.d("notottg",title+message)
buildNotificationChannel()

if(buildNotificationChannel()){
generateNotification(title!!,message!!)
}

}

}
< /code>
Это моя функция CreateenotificationChannel < /p>
private fun buildNotificationChannel():Boolean {

/*var audioAttributes = AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.build()
sound=Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE+"://"+applicationContext.packageName+"/"+R.raw.alert)
Log.d("notisound",sound.toString())*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
val CHANNEL_ID = "merchant_notification"
val CHANNEL_NAME = "Merchant Notification"
var notificationChannel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH).apply {
vibrationPattern=longArrayOf(400, 400, 400, 400, 500, 400, 400, 400, 400)
enableVibration(true)
}
notificationManager= getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(notificationChannel)

//notificationChannel.setSound(sound,audioAttributes)

}
return true

}
< /code>
И это моя функция GenerateNotification < /p>
fun generateNotification(title: String, message: String) {

val intent = Intent(this@CustomMessagingService, MainActActivity::class.java)
var pendingIntent = PendingIntent.getActivity(this@CustomMessagingService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)

var builder: NotificationCompat.Builder =
NotificationCompat.Builder(this, "merchant_notification")
var audioAttributes = AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.build()
sound=Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE+"://"+applicationContext.packageName+"/"+R.raw.alert)
Log.d("notisound",sound.toString())

builder.setAutoCancel(true)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentTitle(title)
.setContentText(message)
.setContentIntent(pendingIntent)
.setSound(sound)

notification = builder.build()
Log.d("notot", notification.toString() + " " + sound.toString())
notificationManager.notify(1, notification)

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
var nb: Notification.Builder = Notification.Builder(this)
nb.setSmallIcon(R.mipmap.ic_launcher_round)
.setAutoCancel(true)
.setSound(sound, audioAttributes)
.setContentTitle(title)
.setContentText(message)
.setContentIntent(pendingIntent)
.build()
notification = nb.notification
notification.flags = Notification.FLAG_AUTO_CANCEL
notificationManager.notify(0, notification)
}

}
< /code>
Мой код манифеста < /p>










Подробнее здесь: https://stackoverflow.com/questions/666 ... ng-created
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»