我正在创建一个应用程序,我需要在通知上显示计时器。我不知道应该怎么做。我尝试了一些方法,但我做不到。请参阅以下通知代码:
public NotificationCompat.Builder createNotification(Context context, String text) {
Intent intent = new Intent(this, MapsActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
final RemoteViews removeWidget = new RemoteViews(context.getPackageName(), R.layout.custom_notification);
removeWidget.setOnClickPendingIntent(R.id.title, pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
boolean running = true;
builder = new NotificationCompat.Builder(context)
.setContentText(text)
.setContentTitle("titulo")
.setSmallIcon(R.drawable.ic_today_black_24dp)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setOngoing(running)
.setContentIntent(
PendingIntent.getActivity(context, 10,
new Intent(context, MapsActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP),
0)
);
builder.setCustomContentView(removeWidget);
notificationManager.notify(0, builder.build());
return builder;
}
如何将计时器(计时器)插入RemoteViews?