My project has several types of notifications. I created an ENUM where I keep the Notification type and id.
final Intent intent = new Intent(getApplicationContext(),MainActivity.class);
intent.putExtra(TYPE, NotificationType.TYPE1.type);
intent.setFlags( Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent open = PendingIntent.getActivity(this, NotificationType.TYPE1.idNotification,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
In MainActivity
, I invoke cancel by passing the id according to the type:
String tipo = extras.getString(NotificationService.TYPE);
if(NotificationService.NotificationType.TYPE1.type.equals(tipo)){
NotificationManager.class.cast(this.getSystemService(Context.NOTIFICATION_SERVICE)).cancel(NotificationService.NotificationType.TYPE1.idNotification);
}
On the Smartphone, it removes correctly, but in Wear, it's still open! If I click again on Wear (from some already closed on the smartphone) it displays a Not Worked! Message
Anyone know if I can force them to quit on Wear?
Is there another way to cancel a Notification?