Reputation: 69
How can i disable vibrating when notification appeared?
I used startForground(int, int);
in PlayerService
class.
Any solutions?
NOTE: I tried many ways but it starts vibrating again.
builder.setDefault(Notification.DEFAULT_ALL);
builder.setVibrate(new long[]{0L})
uilder.setVibrate(new long[]{01, 01})
NotificationManager notificationManager;
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel;
builder = new NotificationCompat.Builder(this);
String title = playlist().get(play_song_id).get(1);
String content = getSongArtists();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
channel = new NotificationChannel("lawanmusic", "lawanmusic", NotificationManager.IMPORTANCE_HIGH);
channel.setLightColor(getColor(R.color.colorAccent));
channel.enableVibration(false);
channel.setVibrationPattern(new long[]{ 01, 01 });
channel.enableVibration(false);
channel.setImportance(NotificationManager.IMPORTANCE_DEFAULT);
builder.setChannelId(channel.getId());
notificationManager.createNotificationChannel(channel);
}
builder.setDefaults(Notification.DEFAULT_ALL | -Notification.DEFAULT_VIBRATE).setVibrate(new long[]{ 0L });
builder.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle().setShowActionsInCompactView(0,1,2).setCancelButtonIntent(null).setMediaSession(new MediaSessionCompat(this, "media").getSessionToken()).setShowActionsInCompactView());
builder.setContentTitle(title);
builder.setContentText(content);
@DrawableRes int icon = R.drawable.play_icon_notification;
builder.setSmallIcon(icon);
builder.setLargeIcon(getSongCover());
PendingIntent pendingIntent = PendingIntent.getActivity(this, Constants.NOTIFICATION_ID, new Intent(this, ActivityMain.class).putExtra("player", true), PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
final PendingIntent prev = PendingIntent.getBroadcast(this, Constants.NOTIFICATION_ID, new Intent(this, PlayerReceiver.class).setAction(PREV_ACTION), PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.notification_prev, "Prev", prev);
final PendingIntent pause = PendingIntent.getBroadcast(this, Constants.NOTIFICATION_ID, new Intent(this, PlayerReceiver.class).setAction(PAUSE_ACTION), PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.notification_pause, "Pause", pause);
final PendingIntent next = PendingIntent.getBroadcast(this, Constants.NOTIFICATION_ID, new Intent(this, PlayerReceiver.class).setAction(NEXT_ACTION), PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.notification_next, "Next", next);
final PendingIntent stop = PendingIntent.getBroadcast(this, Constants.NOTIFICATION_ID, new Intent(this, PlayerReceiver.class).setAction(STOP_ACTION), PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.notification_stop, "Player Off", stop);
builder.setShowWhen(false);
builder.build();
notification.flags = Notification.DEFAULT_ALL | -Notification.DEFAULT_VIBRATE;
notification.vibrate = null;
notification = builder.build();
startForeground(Constants.NOTIFICATION_ID, notification);
Upvotes: 0
Views: 333
Reputation: 111
You could be creating the NotificationChannel with IMPORTANCE_DEFAULT which the documentation says:
Default notification importance: shows everywhere, makes noise, but does not visually intrude.
You probably want IMPORTANCE_LOW:
Low notification importance: shows everywhere, but is not intrusive.
Or IMPORTANCE_MIN:
No sound and does not appear in the status bar
But I can't be sure because I haven't seen all your code surrounding this service
Create and Manage Notification Channels
Upvotes: 1