显示通知 - 启用请勿打扰模式
show notifications - Do Not Disturb mode enabled
有人知道如何在启用静音 mode 时在设备上接收通知吗?
我正在使用网络服务器和 firebase 发送通知推送,当 android 设备处于静音状态时似乎无法收到通知 mode (请勿打扰).
但是,当我将智能手机设为静音 mode 时,我的闹钟仍在响。
然后我们应该能够收到分类为“警报”的通知,即使在 Silence mod 中也是如此。没有?
在静音模式下显示通知的最佳方式是显示全屏意图
val summaryNotification =
NotificationCompat.Builder(
context,
notificationChannelId
)
.setSmallIcon(getSmallIconForNotification())
.setLargeIcon(largeIcon(context))
.setStyle(bigPicStyle)
.setContentTitle(title)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.addAction(
R.drawable.ic_cancel_small,
context.getString(R.string.dismiss),
dismissIntent
)
.setAutoCancel(true)
.setTimeoutAfter(durationInMilliSeconds!!.toLong())
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(
contentIntent(
context,
SUMMARY_NOTIFICATION_ID
)
)
if (!showFull) {
summaryNotification.setSound(sound, AudioManager.STREAM_ALARM)
}
if (showFull) {
summaryNotification.setFullScreenIntent(buildPendingIntent(context, i), true)
}
notificationManager.notify(
SUMMARY_NOTIFICATION_ID,
summaryNotification.build()
)
构建待定意向:
private fun buildPendingIntent(
context: Context,
intent: Intent
): PendingIntent? {
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
当您从 firebase 收到数据时,检查 phone 是否处于活动状态,然后发送适当的通知
val mPowerManager = context!!.getSystemService(Context.POWER_SERVICE) as PowerManager
if (!mPowerManager.isInteractive) {
showFullNotification(true)
}else{
showFullNotification(false)
}
那么你必须创造一个惊人的activity。
在警报中隐藏操作栏activity:
(this as AppCompatActivity?)!!.supportActionBar!!.hide()
并在清单中
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
有人知道如何在启用静音 mode 时在设备上接收通知吗? 我正在使用网络服务器和 firebase 发送通知推送,当 android 设备处于静音状态时似乎无法收到通知 mode (请勿打扰). 但是,当我将智能手机设为静音 mode 时,我的闹钟仍在响。 然后我们应该能够收到分类为“警报”的通知,即使在 Silence mod 中也是如此。没有?
在静音模式下显示通知的最佳方式是显示全屏意图
val summaryNotification =
NotificationCompat.Builder(
context,
notificationChannelId
)
.setSmallIcon(getSmallIconForNotification())
.setLargeIcon(largeIcon(context))
.setStyle(bigPicStyle)
.setContentTitle(title)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.addAction(
R.drawable.ic_cancel_small,
context.getString(R.string.dismiss),
dismissIntent
)
.setAutoCancel(true)
.setTimeoutAfter(durationInMilliSeconds!!.toLong())
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(
contentIntent(
context,
SUMMARY_NOTIFICATION_ID
)
)
if (!showFull) {
summaryNotification.setSound(sound, AudioManager.STREAM_ALARM)
}
if (showFull) {
summaryNotification.setFullScreenIntent(buildPendingIntent(context, i), true)
}
notificationManager.notify(
SUMMARY_NOTIFICATION_ID,
summaryNotification.build()
)
构建待定意向:
private fun buildPendingIntent(
context: Context,
intent: Intent
): PendingIntent? {
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
当您从 firebase 收到数据时,检查 phone 是否处于活动状态,然后发送适当的通知
val mPowerManager = context!!.getSystemService(Context.POWER_SERVICE) as PowerManager
if (!mPowerManager.isInteractive) {
showFullNotification(true)
}else{
showFullNotification(false)
}
那么你必须创造一个惊人的activity。
在警报中隐藏操作栏activity:
(this as AppCompatActivity?)!!.supportActionBar!!.hide()
并在清单中
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.WAKE_LOCK" />