I want to check if app notification is running. I have tried various illustration . It the test always returns false even when the notification is running. Implemented notification as:
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());
and using the snippet below to check if it is running.
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;
}
read this but is was Added in API level 18 and i want something that can work on ics devices. How can i fix this ? Thanks.
edit
pending intent of each remoteView component
protected PendingIntent getPendingSelfIntent(Context context) {
Intent intent = new Intent(context, AppReceiver.class);
return PendingIntent.getBroadcast(context, 0, intent, 0);
}
protected PendingIntent getLaunchZone(Context context) {
Intent intent = new Intent(context, WindowServiceDialog.class);
return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}