首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >setFullScreenIntent在三星安卓系统11中前景不佳

setFullScreenIntent在三星安卓系统11中前景不佳
EN

Stack Overflow用户
提问于 2022-03-15 16:51:02
回答 1查看 102关注 0票数 0

我试着用音频显示呼叫通知,比如什么?

我使用setFullScreenIntent和挂起的意图实现了全屏呼叫通知,如下所示,但在其他设备中,除了三星的OS 11设备外,我还收到了前台通知。

代码语言:javascript
复制
var notificationBuilder: NotificationCompat.Builder? = null
            val ringUri: Uri = Settings.System.DEFAULT_RINGTONE_URI
           var contentView = RemoteViews(packageName, R.layout.call_notification_layout)
            contentView.setOnClickPendingIntent(R.id.imgCallYes, receiveCallPendingIntent)
            contentView.setOnClickPendingIntent(R.id.imgCallNo, cancelCallPendingIntent)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
             notificationBuilder = NotificationCompat.Builder(
                applicationContext,
                CHANNEL_ID
            )
                .setSmallIcon(R.mipmap.ic_launcher)
                 .setContent(contentView)
                 .setCategory(NotificationCompat.CATEGORY_CALL)
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setAutoCancel(true) 
                .setSound(ringUri)
                 .setFullScreenIntent(callDialogPendingIntent, true)
            val notificationChannel = NotificationChannel(
                CHANNEL_ID,
                "My Notifications",
                NotificationManager.IMPORTANCE_HIGH
            )
            val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
            // Configure the notification channel.
            val att = AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
                .build()
            notificationChannel.setSound(ringUri, att)
            notificationChannel.description = "body"
            notificationChannel.enableLights(true)
            notificationChannel.lightColor = Color.RED
            notificationChannel.vibrationPattern = longArrayOf(0, 1000, 500, 1000)
            notificationChannel.enableVibration(true)
            notificationManager.createNotificationChannel(notificationChannel)
        } else {
             notificationBuilder =
                NotificationCompat.Builder(applicationContext, CHANNEL_ID)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContent(contentView)
                    .setAutoCancel(true)
                    .setCategory(NotificationCompat.CATEGORY_CALL)
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setSound(ringUri)
                    .setFullScreenIntent(callDialogPendingIntent, true)
        }

        var incomingCallNotification: Notification? = null
        if (notificationBuilder != null) {
            incomingCallNotification = notificationBuilder.build()
        }
        startForeground(NOTIFICATION_ID, incomingCallNotification)
EN

回答 1

Stack Overflow用户

发布于 2022-03-31 17:29:18

在Android 12中,我添加了PendingIntent.FLAG_IMMUTABLE或PendingIntent.FLAG_UPDATE_CURRENT作为暂挂的意图,现在通知来了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71486024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档