【发布时间】:2018-03-15 04:50:56
【问题描述】:
在 Android 8.0 (Oreo) 上,每次通知进度有更新时,它都会振动。所以手机在这个过程中振动了100次。这只发生在 Android 8.0 上所以我可以假设我对他们的 API 有一些不当使用。我正在寻求帮助以停止通知的每次进度更新时的振动。这是我的代码:
建筑通知
mNotifyManager = (NotificationManager) mActivity.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createChannel(mNotifyManager);
mBuilder = new NotificationCompat.Builder(mActivity, "FileDownload")
.setSmallIcon(android.R.drawable.stat_sys_download)
.setColor(ContextCompat.getColor(mActivity, R.color.colorNotification))
.setContentTitle(mFile.getName())
.setContentText(mActivity.getResources().getString(R.string.app_name))
.setProgress(0, 0, true);
mNotifyManager.notify(mFile.getId().hashCode(), mBuilder.build());
创建通道方法
@TargetApi(26)
private void createChannel(NotificationManager notificationManager) {
String name = "FileDownload";
String description = "Notifications for download status";
int importance = NotificationManager.IMPORTANCE_MAX;
NotificationChannel mChannel = new NotificationChannel(name, name, importance);
mChannel.setDescription(description);
mChannel.enableLights(true);
mChannel.setLightColor(Color.BLUE);
notificationManager.createNotificationChannel(mChannel);
}
onProgress
@Override
public void onProgress(File file, double progress, long downloadedBytes, long totalBytes) {
mBuilder.setProgress(100, (int) (progress * 100), false);
mNotifyManager.notify(file.getId().hashCode(), mBuilder.build());
}
【问题讨论】:
-
@CommonsWare 这不起作用
-
您能否详细解释一下在这种情况下“不起作用”是什么意思?
-
@CommonsWare 设置 enableVibration(false) 不会停止振动
标签: android notifications