Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notification vibrates on each progress update

Tags:

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());   } 
like image 643
Adrian Le Roy Devezin Avatar asked Oct 03 '17 21:10

Adrian Le Roy Devezin


People also ask

Why are my notifications vibrating?

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.

How do I show progress notifications on Android?

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).


1 Answers

Using setOnlyAlertOnce(true) on your NotificationCompat.Builder when initially building the notification should do the trick.

like image 130
Henning Dodenhof Avatar answered Sep 28 '22 20:09

Henning Dodenhof