Khi trên Android 8.0 (Oreo), mỗi khi có bản cập nhật cho tiến trình của thông báo, nó rung. Vì vậy, điện thoại rung 100 lần trong quá trình này. Điều này chỉ xảy ra trên Android 8.0 Vì vậy, tôi có thể giả định rằng tôi đang sử dụng API không đúng. Tôi yêu cầu trợ giúp trong việc dừng rung trên mỗi lần cập nhật tiến trình của thông báo. Đây là mã của tôi:Thông báo rung trên mỗi cập nhật tiến trình
Xây dựng Thông báo
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());
Tạo phương pháp Kênh
@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());
}
https://developer.android.com/reference/android/app/NotificationChannel.html#enableVibration(boolean) – CommonsWare
@CommonsĐiều này không hoạt động –
Bạn có thể giải thích chi tiết những gì "không hoạt động" có nghĩa là trong ngữ cảnh này? – CommonsWare