Android 是否可以在锁屏中显示不同的通知布局?
我想在锁屏中显示不同的通知布局。我正在使用远程视图,我想知道是否可以从notifications creator类创建两个不同的通知,具体取决于它是否处于锁定屏幕 是否存在此项的任何标志Android 是否可以在锁屏中显示不同的通知布局?,android,notifications,remoteview,Android,Notifications,Remoteview,我想在锁屏中显示不同的通知布局。我正在使用远程视图,我想知道是否可以从notifications creator类创建两个不同的通知,具体取决于它是否处于锁定屏幕 是否存在此项的任何标志 谢谢。编辑:也许本教程可以帮助您 旧的: 您可以创建两个具有不同优先级的通知,如中所述 并对锁屏上显示的通知使用高优先级 问题是您想要创建一个只在锁屏上可见的通知。此功能本身不存在。使用上述解决方案,您将在解锁屏幕中显示两个通知 您可以收听屏幕锁,如以下回答所示: 然后,您可以取消具有高优先级的通知,只使
谢谢。编辑:也许本教程可以帮助您 旧的: 您可以创建两个具有不同优先级的通知,如中所述 并对锁屏上显示的通知使用高优先级 问题是您想要创建一个只在锁屏上可见的通知。此功能本身不存在。使用上述解决方案,您将在解锁屏幕中显示两个通知 您可以收听屏幕锁,如以下回答所示: 然后,您可以取消具有高优先级的通知,只使用具有默认优先级的通知,并在必要时更新此通知
如果您想更好地描述您想要实现的目标,我可以给您一个代码示例编辑:也许本教程可以帮助您 旧的: 您可以创建两个具有不同优先级的通知,如中所述 并对锁屏上显示的通知使用高优先级 问题是您想要创建一个只在锁屏上可见的通知。此功能本身不存在。使用上述解决方案,您将在解锁屏幕中显示两个通知 您可以收听屏幕锁,如以下回答所示: 然后,您可以取消具有高优先级的通知,只使用具有默认优先级的通知,并在必要时更新此通知 如果你想更好地描述你想要完成的事情,我可以给你一个代码示例是的,你可以做到。 您可以使用
Settings.System.putString(context.getContentResolver(),Settings.System.NEXT\u ALARM\u格式化,yourMessage)代码>显示屏幕锁定时的通知。
如果屏幕未锁定,则使用
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher) // notification icon
.setContentTitle("Notification!") // title for notification
.setContentText("Hello word") // message for notification
.setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
现在您可以显示通知。如果您检测到您的屏幕是否被锁定,则可以使用此代码
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean locked = km.inKeyguardRestrictedInputMode();
享受你的代码:)是的,你可以做到。
您可以使用Settings.System.putString(context.getContentResolver(),Settings.System.NEXT\u ALARM\u格式化,yourMessage)代码>显示屏幕锁定时的通知。
如果屏幕未锁定,则使用
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher) // notification icon
.setContentTitle("Notification!") // title for notification
.setContentText("Hello word") // message for notification
.setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
现在您可以显示通知。如果您检测到您的屏幕是否被锁定,则可以使用此代码
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean locked = km.inKeyguardRestrictedInputMode();
享受你的代码:)