I am defining a custom vibration for a specific functionality when notification is received.
However, when the phone screen is off, the custom vibration plays along with the default notification vibration.
I tried to put phone to silent mode and remove it from silent mode programmatically and also tried to use a partial wakelock, suspecting that when the CPU is off, then the default vibration is also thrown, but both approaches don't seem to work.
I also tried to mute the default audio and the vibration and restore it upon completion of my task on receiving a notification, but that only helps in masking the default notification sound, not the default vibration.
//Trying to mute the notification sound and vibration
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
//Restoring the defaults
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, defaultNotifVolume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
Please let me know how to disable/enable the default notification vibration programmatically.
try to do this
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this);
this will lead to a pattern of vibrate use the notification Builder and remove the set vibrate ,this will disable the vibrate
this is my example of handling the sound and vibrate ex:
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText(body)
.setContentTitle(title)
.setSound(soundUri)
.setLargeIcon(icon)
.setSound(soundUri)
.setLights(Color.parseColor("#ffb400"), 50, 10)
.setVibrate(new long[]{500, 500, 500, 500})
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
This is not possible (maybe with root?).
Apps cannot interfere with other apps so even if it would be possible it would be against the Google Play rules.
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