Android 奇怪的通知行为';s进度条

Android 奇怪的通知行为';s进度条,android,notifications,Android,Notifications,我正在制作下载意图服务,该服务应通过3个步骤下载照片并显示通知: 1) 通知,如果已经有下载过程,则显示照片正准备下载的文本; 2) 通知显示照片正在下载并显示进度条; 3) 通知显示照片已下载 只有1个问题,准备显示进度条的通知 这是服务代码: public class PhotoDownloadService extends IntentService { private static final String TAG = "PhotoDownloadService";

我正在制作下载意图服务,该服务应通过3个步骤下载照片并显示通知: 1) 通知,如果已经有下载过程,则显示照片正准备下载的文本; 2) 通知显示照片正在下载并显示进度条; 3) 通知显示照片已下载

只有1个问题,准备显示进度条的通知

这是服务代码:

public class PhotoDownloadService extends IntentService {

    private static final String TAG = "PhotoDownloadService";
    private Notification.Builder basicNotification;
    private NotificationManager notifManager;
    private int currentId = 1;

    public PhotoDownloadService() {
        super("PhotoDownloadService");
    }

    @Override
    public void onCreate() {
        basicNotification = new Notification.Builder(this)
                .setContentTitle(getString(R.string.app_name))
                .setSmallIcon(R.mipmap.ic_launcher);
        notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "onStartCommand with id : " + startId);
        Notification prepareNotification = basicNotification
                .setContentText(intent.getStringExtra("text") + ": prepare for download")
                .build();
        notifManager.notify(startId, prepareNotification);
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Log.i(TAG, "onHandleIntent");
        Notification downloadingNotification = basicNotification
                .setContentText(intent.getStringExtra("text") + " is downloading")
                .setProgress(0, 0, true)
                .build();
        notifManager.notify(currentId, downloadingNotification);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Notification finishNotification = basicNotification
                .setContentText(intent.getStringExtra("text") + " was downloaded")
                .setProgress(0, 0, false)
                .build();
        notifManager.notify(currentId, finishNotification);
        currentId++;
    }
}