Как настроить уведомление CallType с мелодией звонка по умолчанию для звонковAndroid

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

Сообщение Anonymous »

Я использую push-уведомление fcm для запуска вызовов и подключения к сокету и webrtc.
Я установил обычный поток с помощью NotificationChannel и установил для него звук, но он по-прежнему звучит для звука уведомления по умолчанию, а не для звука звук звонка. любая помощь будет оценена по достоинству. Заранее спасибо
ниже код

Код: Выделить всё

fun createNotification(context: Context, contactInfo: UserDetail)
{
val intent = Intent(context, VideoCallActivity::class.java)
intent.putExtra("Contact", contactInfo)
intent.putExtra("notificationId", INCOMING_CALL_NOTIFICATION_ID)
intent.putExtra("inComingCall", true)
val acceptCallIntent = PendingIntent.getActivity(context, REQUEST_CODE_ACCEPT_CALL, intent, PendingIntent.FLAG_IMMUTABLE)

val rejectIntent = Intent(context, HomeActivity::class.java)
rejectIntent.putExtra("Contact", contactInfo)
rejectIntent.putExtra("notificationId", INCOMING_CALL_NOTIFICATION_ID)
rejectIntent.putExtra("fromCall", true)
rejectIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
val rejectCallIntent = PendingIntent.getActivity(context, REQUEST_CODE_REJECT_CALL, rejectIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)

val ringingIntent = Intent(context, RingingActivity::class.java)
ringingIntent.putExtra("Contact", contactInfo)
ringingIntent.putExtra("notificationId", INCOMING_CALL_NOTIFICATION_ID)
ringingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
val ringingCallIntent = PendingIntent.getActivity(context, REQUEST_CODE_RINGING_CALL, ringingIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)

setupNotification(context, contactInfo, acceptCallIntent, rejectCallIntent, ringingCallIntent, AppCompatResources.getDrawable(context, R.drawable.profile_avatar))
}

Код: Выделить всё

private fun setupNotification(
context: Context,
contactInfo: UserDetail,
acceptCallIntent: PendingIntent,
rejectCallIntent: PendingIntent,
ringingCallIntent: PendingIntent,
resource: Drawable?
) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

val channelId = createNotificationChannel(context, notificationManager)

val name = contactInfo.name

val builder = NotificationCompat.Builder(context, channelId!!)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle(context.getString(R.string.incoming_call))
.setContentText(context.getString(R.string.incoming_call_from, name))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setOngoing(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setFullScreenIntent(ringingCallIntent, true)
.setOngoing(true)
.setVibrate(longArrayOf(1000, 1000, 1000, 1000))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE))

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
{
val icon = IconCompat.createWithBitmap(AppCompatResources.getDrawable(context, R.drawable.profile_avatar))
val caller = Person.Builder()
.setIcon(icon)
.setName(name)
.setImportant(true)
.build()

val notificationStyle = NotificationCompat.CallStyle.forIncomingCall(caller, rejectCallIntent, acceptCallIntent).setIsVideo(true)
builder.setStyle(notificationStyle)
}
else
{
builder.addAction(
R.drawable.ic_answer, "Accept", acceptCallIntent
)
builder.addAction(
R.drawable.ic_reject, "Reject", rejectCallIntent
)
}

builder.setLargeIcon(defaultAvatar)

if (ActivityCompat.checkSelfPermission(
context,
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
) {
notificationManager.notify(INCOMING_CALL_NOTIFICATION_ID, builder.build())
}
}

Код: Выделить всё

private fun createNotificationChannel(context: Context, notificationManager: NotificationManager):  String?
{
val ringtoneUri: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)
val audioAttributes = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.build()

val channel = NotificationChannel(
INCOMING_CALL_CHANNEL_ID,
"Incoming Call Notifications",
NotificationManager.IMPORTANCE_HIGH
).apply {
description = "Channel for incoming call notifications"
enableLights(true)
enableVibration(true)
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
setSound(ringtoneUri, audioAttributes)
}
Я даже пытался скопировать файл мелодии звонка в кеш и использовать его, он может воспроизводить менеджер мелодий звонка, но его URI невозможно использовать в уведомлении.
Любая помощь будет оценена по достоинству

Подробнее здесь: https://stackoverflow.com/questions/790 ... -for-calls
Ответить

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

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

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

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

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