When on Android 8.0 (Oreo), every time there is an update to the progress of the notification, it vibrates. So the phone vibrates 100 times in the process. This only happens on Android 8.0 So i can assume I am having some improper use of their API. I am asking for help in stopping the vibration on each progress update of the notification. Here is my code:
Building Notification
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());
Create Channel method
@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()); }
If your Android phone keeps vibrating randomly, check your notification settings for each app installed on your device. You can use Nova Launcher to check which of your apps sent the most recent notification. Then install the latest app and Android updates and enable Safe Mode.
To display a determinate progress bar, add the bar to your notification by calling setProgress(max, progress, false) and then issue the notification. The third argument is a boolean that indicates whether the progress bar is indeterminate (true) or determinate (false).
Using setOnlyAlertOnce(true)
on your NotificationCompat.Builder
when initially building the notification should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With