我正在开发一个带有服务的应用程序,该服务显示通知区域中的计时器的进度(带有进度条和文本).我已经在下面提取了一个具有相同问题的简单示例.
服务代码:
public class TNService extends Service {
private NotificationManager nm;
private Notification notification;
private RemoteViews remoteView;
@Override
public void onCreate () {
nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notification = new Notification(android.R.drawable.stat_sys_download,
"My notification",
System.currentTimeMillis());
remoteView = new RemoteViews(this.getPackageName(),
R.layout.notification);
remoteView.setImageViewResource(R.id.icon, android.R.drawable.stat_sys_download);
remoteView.setTextViewText(R.id.text, "");
remoteView.setProgressBar(R.id.progress, 100, 0, false);
notification.flags = Notification.FLAG_NO_CLEAR;
notification.contentView = remoteView;
notification.contentIntent = PendingIntent.getActivity(this, 0, new Intent(this,
TNActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
Timer timer = new Timer ();
timer.schedule(new TNTask(this), 0, 200);
}
@Override
public IBinder onBind(Intent arg0) {
return null; …Run Code Online (Sandbox Code Playgroud)