0
I have the following method below:
public NotificationCompat.Builder createNotification(Context context) {
Intent intent = new Intent(this, MapsActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
boolean running = true;
builder = new NotificationCompat.Builder(context)
.setContentText("conteúdo")
.setContentTitle("titulo")
.setSmallIcon(R.drawable.ic_today_black_24dp)
.setAutoCancel(false)
.setOnlyAlertOnce(true)
.setOngoing(running)
.setContentIntent(
PendingIntent.getActivity(context, 10,
new Intent(context, MapsActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP),
0)
)
.addAction(running ? R.drawable.ic_stop_black_24dp
: R.drawable.ic_play_arrow_black_24dp,
running ? "Pause"
: "play",
pIntent)
.addAction(R.drawable.ic_stop_black_24dp, "Stop",
pIntent);
notificationManager.notify(0, builder.build());
return builder;
}
In which you launch a notification in the status bar, as shown below in the first notification:
To loop the notification I do this way:
NotificationCompat.Builder notification = createNotification(this);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, notification.build());
I would like to create a Chronometer
in a notification, exactly as it appears in the Strava notification (second image notification), as shown above.
How to create a Chronometer
in a notification?
@ramaral give me a help! =)
– viana
Would using a
RemoveView
wouldn’t it? Although I’ve never used it I would guess it’s worth a test.– Wakim
@Wakim tried in a way, picking up the web, but it turned out that the insertion method is deprecated. I will search a little more.
– viana
@Wakim answered the question there in the gringos, but I haven’t heard back yet. = D
– viana
I agree with @Wakim. Remoteviews allows you to use a Chronometer view. See setChronometer()
– ramaral
@ramaral I even researched about the class
RemoteViews
and notRemoveView
, and I found some results yesterday. I ended up putting an answer. If you have any suggestions, or disagreement about something, just a touch.– viana
That’s it. Now all that remains is to implement the PAUSE and STOP buttons :)
– ramaral
@ramaral yes, I will do this, then edit the answer! = D
– viana