我正在制作的应用程序具有文件传输功能,我在通知中显示了它的进度,并提供了停止传输的选项。问题是,每次调用NotificationManager.notify (每次进度更改时都必须调用它)时,都会播放系统通知声音(这会导致大量垃圾邮件),并且用于停止传输的按钮变得不可用。
如果不更新进度条,则允许按下“停止传输”按钮。我注意到的另一件事是,声音垃圾邮件出现在Android 8.x上,而不是5.x上。
创建通知:
mBuilder = new NotificationCompat.Builder(cont, "default")
.setSmallIcon(R.drawable.file)
.setContentTitle("File transfer app")
.setContentText((down ? "Downloading " : "Uploading ") + fileName)
.setAutoCancel(false)
.setProgress(100, 0, indeterminate);
Intent notifyButton = new Intent();
notifyButton.setAction("STOP_TRANSFER");
notifyButton.putExtra("id", notifId);
PendingIntent pendingIntent = PendingIntent.getBroadcast(cont, notifId, notifyButton, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.addAction(R.drawable.close, "Stop transfer", pendingIntent);
all.add(this);
mNotificationManager.notify(notifId, mBuilder.build());更新进度:
mBuilder.setProgress(this.max, progress, indeterminate);
mNotificationManager.notify(notifId, mBuilder.build());我希望进度条可以正常更新,而不会在每次移动时发出声音,并允许我随时取消传输。
我是不是做错了什么?
发布于 2019-07-02 07:02:45
如果您的更新通知持续不断地通知进度,则可能需要调用mNotificationManager.cancel()。
if(update){
mNotificationManager.cancel(notifId)
}
mNotificationManager.notify(notifId, mBuilder.build());https://stackoverflow.com/questions/54042562
复制相似问题