我想检查应用通知是否正在运行。我尝试了各种illustration。即使通知正在运行,测试也始终返回false。实施通知为:
SELECT D.NAME as DeptName, T.STATUS as Status, COUNT(1) as Count
FROM TICKETS T
, DEPARTMENT D
WHERE T.FK_DEPT_ID = D.PK_DEPT_ID
GROUP BY D.NAME , T.STATUS;
并使用下面的代码段来检查它是否正在运行。
NotificationManager mNotificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.zone_recharge_notification);
remoteViews.setOnClickPendingIntent(R.id.zn_recharge, getPendingSelfIntent(context));
remoteViews.setOnClickPendingIntent(R.id.zn_launch, getLaunchZone(context));
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.zone_holo_logo_48)
.setOngoing(true)
.setOnlyAlertOnce(true)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContent(remoteViews)
.setAutoCancel(false);
mNotificationManager.notify(AppConstant.RECHARGE_ME_NOTIFICATION_ID, mBuilder.build());
阅读this但是在API级别18中添加,我想要一些可以在ics设备上运行的东西。我怎样才能解决这个问题 ?感谢。
修改
每个remoteView组件的待定意图
public static boolean isNotificationVisible(Context context) {
Intent notificationIntent = new Intent(context, WindowServiceDialog.class);
PendingIntent test = PendingIntent.getService(context, AppConstant.RECHARGE_ME_NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_NO_CREATE);
return test != null;
}
答案 0 :(得分:-1)
使用mBuilder.setDeleteIntent(deletePendingIntent);
(javadoc),您可以在通知被清除时为触发的通知设置待处理意图。然后创建一个注意删除的IntentService(或任何其他Intent接收器)并将该信息存储在某处(例如SharedPreferences)。在isNotificationVisible
操作中,您可以检查sharedPref中的值。