如何停止通知进度栏?

时间:2019-05-14 21:59:20

标签: android progress-bar android-progressbar

我有这段代码可以创建通知进度栏,并且可以正常工作...  现在我想做的是创建一个函数来停止通知并更改通知栏上的文本,这可以吗?

 final NotificationCompat.Builder notification = new 
    NotificationCompat.Builder(this, CHANNEL_2_ID)
                    .setSmallIcon(R.drawable.ic_cloud_download_black_24dp)
                    .setContentTitle("Download")
                    .setContentText("Download in progress")
                    .setPriority(NotificationCompat.PRIORITY_LOW)
                    .setOngoing(true)
                    .setContentIntent(contentIntent)
                    .setOnlyAlertOnce(true)
                    .setProgress(progressMax, 0, true);

            notificationManager.notify(2, notification.build());

            new Thread(new Runnable() {
                @Override
                public void run() {
                    SystemClock.sleep(2000); 
                }
            }).start();

这给我一个错误:

 public void onDownloadComplete() {
    notificationManager.cancel(0);
    //Set Title -> downloaded
  }

0 个答案:

没有答案