Android Wear: a timer like a device wear notification board

I am working on a Pomodoro app for Android Wear.

I want to make it look like a standard UI / UX timer , I assume that it is implemented using a notification display / update with a timer as a header, so I'm showing a notification and periodically updating it from the 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); } 

The problem of dissatisfaction with such a solution blinks from notificaiton.

Any ideas how the escape blinks? Or maybe another way to achieve targeted behavior?

+2
android android wear
Aug 26 '14 at 6:59
source share
1 answer

To update current / existing notification -

  • Use Same Id Notifications in Builder
  • 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()); } }

0
Aug 26 '14 at 10:03
source share



All Articles