2

I'm working on implementation of Pomodoro app for Android Wear.

I want to make similar to standard timer UI/UX, I guess it's implemented using displaying/updating notification with timer as title, so I'm showing notification and updating it periodically from Service:

private void updateNotification() {
    Intent stopActionIntent = new Intent(this, PomodoroActivity.class);
    stopActionIntent.setAction(PomodoroActivity.ACTION_STOP);
    PendingIntent stopActionPendingIntent = PendingIntent.getActivity(this, 0, stopActionIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Action stopAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_stop,
            getString(R.string.stop_pomodoro),
            stopActionPendingIntent)
            .build();

    Notification notification = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_pomodoro_timer))
            .setContentTitle(convertDiffToTimer(System.currentTimeMillis(), timerDeadlineMs))
            .setPriority(Notification.PRIORITY_MAX)
            .setOngoing(true)
            .extend(new NotificationCompat.WearableExtender().addAction(stopAction))
            .build();

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(1, notification);
}

Unpleasure problem with such solution is blinking of notificaiton.

Any ideas how escape blinking? Or maybe other way to achieve target behaviour?

AlexKorovyansky
  • 4,873
  • 5
  • 37
  • 48

1 Answers1

0

To update ongoing/existing notification -

  1. Use Same Id of Notification in Builder
  2. Use .setOnlyAlertOnce(true)

NotificationCompat.Builder notificationBuilder; public void generateNotificationForTimer(String timeInString, boolean isFirstTime) { if (isFirstTime) { notificationBuilder = new NotificationCompat.Builder(this) .setStyle(new NotificationCompat.BigPictureStyle()) .setOnlyAlertOnce(true) .setContentTitle("Timer Notification Demo") .setContentText("Time - " + timeInString) .setSmallIcon(R.drawable.common_signin_btn_icon_dark); NotificationManagerCompat.from(this).notify(110, notificationBuilder.build()); } else { notificationBuilder.setContentText(timeInString); NotificationManagerCompat.from(this).notify(110, notificationBuilder.build()); } }

Vintesh
  • 1,657
  • 1
  • 24
  • 31
  • It is working, I have tested my code with Emulator as well as on LG Wear. Check this demo project - [Sample Project on GitHub](https://github.com/vintesh/android-wear-samples) – Vintesh Sep 12 '14 at 05:26
  • Also still blinking on my side (LG G Watch). – Aladin Q Oct 24 '14 at 15:06
  • I had the same issue on my Samsung Gear Live. What I did is to remove the app icon on the notification card to hide the blinking effect with `setHintHideIcon(true)` – nicolas Oct 24 '14 at 15:41
  • @nicolas & others - I don't know if you have tried my GITHUB project or not. I double checked that, it is working fine for me. Can you share your code snippet or project link so that i can resolve issue? – Vintesh Nov 02 '14 at 19:02
  • It seems that it is because you use the BigPicture style for your notification that does not show the app icon. I guess that's why you do not see the notification blinking... – nicolas Nov 05 '14 at 08:53
  • 1
    The solution seems to use `setUsesChronometer` and `setWhen` properties instead of directly updating the time. An example that works here https://github.com/AlexKorovyansky/WearPomodoro – nicolas Nov 06 '14 at 09:13