OnePlus3 Oreo - ForegroundService通知始终是可听见的

时间:2018-06-05 10:15:14

标签: notifications android-8.0-oreo oneplusthree notification-channel

尝试在OnePlus3上迁移到Oreo,但是当我尝试使用ForegroundService时,通知始终是可听见的(或不可见)。

这是我做的事情

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    NotificationChannel(CHANNEL_ID, "FgService", NotificationManager.IMPORTANCE_MIN).apply {
        description = "Running man channel"
        setSound(Uri.fromFile(silenceFile), AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()) // tried without it, tried setSound(null, null)... no luck
        enableLights(false)
        (getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).createNotificationChannel(this)
    }
}

val notificationIntent = Intent(this, MainActivity::class.java)
val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0)
val notificationBuilder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    Notification.Builder(this, CHANNEL_ID)
} else {
    @Suppress("DEPRECATION")
    Notification.Builder(this)
}
val builder =  notificationBuilder.setContentTitle(getText(R.string.notification_title))
        .setContentText(getText(R.string.notification_message))
        .setSmallIcon(R.drawable.ic_bug_report_white_24dp)
        .setContentIntent(pendingIntent)
        .setOnlyAlertOnce(true)
        .setTicker(getText(R.string.ticker_text))
startForeground(ONGOING_NOTIFICATION_ID, builder.build())

请注意,我尝试使用setSound(null,null),并且如代码所示,我尝试播放静音铃声。没有运气。

我在模拟器上尝试了相同的代码,它就像一个魅力。在OnePlus3上 - 它总是通过弹出通知执行恼人的ping噪音: - (

如果没有定义频道,通知就不会出现。这不是理想的行为。

有什么建议吗?

由于

0 个答案:

没有答案