android - 如何在锁定屏幕上显示 android 推送通知?
问题描述
我面临在锁定屏幕上显示推送通知的问题。我能够收到通知,但无法在锁定屏幕上显示它们。
Notification notification;
notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
.setAutoCancel(true)
.setContentTitle(title)
.setContentIntent(resultPendingIntent)
.setSound(alarmSound)
//.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setWhen(getTimeMilliSec(timeStamp))
.setSmallIcon(R.drawable.loader)
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
.setContentText(message)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) //to show content on lock screen
.setPriority(NotificationCompat.PRIORITY_HIGH)
.build();
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(count, notification);
我也尝试过使用 PowerManager,但它只唤醒了锁定屏幕,但没有在屏幕上显示通知。
PowerManager powerManager = (PowerManager) mContext.getSystemService(POWER_SERVICE);
if (!powerManager.isInteractive()){ // if screen is not already on, turn it on (get wake_lock for 10 seconds)
PowerManager.WakeLock wl = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"MH24_SCREENLOCK");
wl.acquire(10000);
PowerManager.WakeLock wl_cpu = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MH24_SCREENLOCK");
wl_cpu.acquire(10000);
}
由于我是 android 新手,我无法解决这个问题。请帮帮我。
解决方案
推荐阅读
- java - UI 观察 LiveData
- > 显示新添加和新删除的对象,但不显示更新或更改
- sql - SQL 函数在没有主键的表中列出列
- javascript - setTimeout 函数触发两次回调
- java - 使用 @DynamicPropertySource 的 TestContainers、Spring Webflux、JUnit 5、MySQLR2DBCDatabaseContainer
- vba - 为什么 VBA 认为 -1 < 3 < 2 为真?
- javascript - 仅当使用键盘而不是鼠标导航时,如何在 extjs 中聚焦元素?
- spring-boot - Spring Boot:在 YAML 文件中激活配置文件时出错
- java - 不同的构造函数(LOMBOK)
- apache-spark - Spark 内存使用量不断增加,而训练模型仍在继续
- linux - 多个文件的 Gnu/Linux (Bash) 批量命令