Android 如何在锁屏上显示安卓推送通知?
我面临在锁屏上显示推送通知的问题。我能够接收通知,但无法在锁屏上显示它们Android 如何在锁屏上显示安卓推送通知?,android,push-notification,notifications,Android,Push Notification,Notifications,我面临在锁屏上显示推送通知的问题。我能够接收通知,但无法在锁屏上显示它们 Notification notification; notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0) .setAutoCancel(true) .setContentTitle(title) .setContentIntent(resultPendingInt
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新手,我无法解决这个问题。请帮助我。手机解锁后,您的通知是否会显示在状态栏中?@Christopher感谢您的快速重播,通知会正确显示在状态栏上,但手机本身已配置为在锁定屏幕上显示通知?作为用户,您可以控制是否希望在锁屏上看到通知。@Christopher非常感谢。我尝试了您建议的方法,效果很好。但他们是否可以通过编程自动选择“在锁屏上显示通知”选项卡?当然,您不能自动操作此设置,但您可以尝试引导用户进入设置->