well, it seems that if I send notification with ID (ongoing ID = 0)
Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE
then it will stay forever there;]
and if I send other notifications to the same ID (0), icon and intents
will update but flags stay :/
I dont know if this is a bug in API 7 but it just dont make sens to
me.
when I sent notification with Notification.FLAG_ONLY_ALERT_ONCE with
different ID(ex. 1) then it was classified as simple notification and
I could easily clear it from expanded menu.
just by sending same notification to previous ID (0) it was classified
as ongoing and I cant cancel it anyhow!
I also tried to save reference to "ongoing" notification and then re-
notify it with other PendingIntent and flags but it has no effect!
my current code of the service
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
Log.d(TAG, "start notification");
startStatusBarNotification();
//do other stuff
// We want this service to continue running until it is explicitly
stopped, so return sticky.
return START_STICKY;
}
private void startStatusBarNotification()
{
Log.d(TAG, "startStatusBarNotification.");
final int icon = R.drawable.stbar_icon_fail;
final long when = System.currentTimeMillis();
final Notification notification = new Notification(icon,
getString(R.string.notify_title), when);
final Intent notificationIntent = new Intent(this,
MyActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent contentIntent =
PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(this,
getString(R.string.notify_title), expandText, contentIntent);
notification.flags = Notification.FLAG_ONGOING_EVENT |
Notification.FLAG_FOREGROUND_SERVICE;//| Notification.FLAG_NO_CLEAR
Log.d(TAG, "notify send.");
final NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(SERVICE_ONGOING_NOTIFICATION_ID,
notification);//ID = 0
}
@Override
public void onDestroy()
{
Log.d(TAG, "clear status bar notification.");
cancelNotification();
super.onDestroy();
}
private void cancelNotification()
{
final int icon = R.drawable.stbar_icon_exit;
final long when = System.currentTimeMillis();
final Notification notification = new Notification(icon,
getString(R.string.notify_title), when);
final PendingIntent contentIntent =
PendingIntent.getActivity(this, 0, null,
PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(this,
getString(R.string.notify_stopping_title),
getString(R.string.notify_stopping_text), contentIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;
final NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(SERVICE_ONGOING_NOTIFICATION_ID); //
NOTHING HAPPENS
mNotificationManager.notify(SERVICE_ONGOING_NOTIFICATION_ID,
notification); //ID = 0 but if this was changed to 1 cancel
notification can be cleared :/
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en