Android 如何找到已展开或未展开的通知视图
我使用以下代码显示通知,它工作正常。我正在寻找一个侦听器,从中我可以知道通知是否已扩展 如果通知已展开,我想打开应用程序,或者打开应用程序的特定活动Android 如何找到已展开或未展开的通知视图,android,android-notifications,Android,Android Notifications,我使用以下代码显示通知,它工作正常。我正在寻找一个侦听器,从中我可以知道通知是否已扩展 如果通知已展开,我想打开应用程序,或者打开应用程序的特定活动 Intent intent= new Intent(context, Activity1.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, getNextRandom(), intent
Intent intent= new Intent(context, Activity1.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, getNextRandom(), intent, 0);
Builder newBuilder newBuilder = new Notification.Builder(context);
newBuilder.setContentTitle(title)
.setContentText(subtitle)
.setAutoCancel(true)
.setSmallIcon(R.drawable.icon)
.setTicker(notificationMessage)
.setContentIntent(pendingIntent);
Notificationnotification = new Notification.BigTextStyle(newBuilder)
.setBigContentTitle(notificationTitle)
.bigText(text)
.build();
让我知道是否有办法做到这一点?没有办法知道通知是否打开。。。您可以做的是在扩展通知中添加按钮,即按下按钮的行为与按下通知本身的行为不同。可能没有直接的方法,但下面的黑客可能会有所帮助 您可以使用自定义通知布局并使用RemoteView,设置SetOnClickPendingEvent为整个视图启动服务,以便在单击通知时收到通知 当用户单击通知时,服务启动,并显示来自服务的新扩展自定义布局(用新通知替换旧通知) 可能还可以使用startforeground显示来自同一服务的初始通知,这样您的应用程序不会被终止,并且可以更快地接收到视图单击,因为服务已经在运行,更改视图的响应时间较短
有关remoteview和从通知启动服务的信息,请参见。单击。我看到这种情况的唯一方法是使用
remoteview
。为默认和扩展状态创建自己的布局。在单击时为每个布局设置不同的悬挂内容。最后,设置builder.setContent(defaultRemoteView)
。和notification.bigContentView=expandedRemoteViews代码>。但是如果通知被展开,我点击通知而不是按钮,则您的案例将不起作用您是对的。。。但我的回答是以“无法知道通知是否打开”开始的,因为通知可以通过上下滑动展开/折叠,而无需单击。