¿Hay opción al crear una notificación en Android para que, no suene y no vibre?
Gracias
Stack Overflow en español es un sitio de preguntas y respuestas para programadores y profesionales de la informática. Solo te toma un minuto registrarte.
Regístrate para unirte a esta comunidadSi, es posible, con este método puedes crear una notificación
y como y donde controlar el sonido
y la vibración
de la misma.
public void Notification(){
int color = getResources().getColor(R.color.Standard);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "my_channel_id_01";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@SuppressLint("WrongConstant") NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_MAX);
// Configure the notification channel.
notificationChannel.setDescription("Informacion");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000}); //<--- Aqui defines intervalos de vibracion
notificationChannel.enableVibration(true); //<--- Aqui controlas la vibracion
assert notificationManager != null;
notificationManager.createNotificationChannel(notificationChannel);
notificationBuilder.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.addAction(R.drawable.simplebutton, "Nombre de boton en notificacion", actionPendingIntent)//actionPendingIntent, es el intent que se ejecutara cuando se clickee el boton de la notificacion.
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.drawable_icon_notification)
.setContentTitle("Titulo")
.setColor(color)
.setSound(Uri.parse("android.resource://"+getPackageName()+"/" + R.raw.beeep)) //<--Aqui estableces el sonido
.setContentText("Texto que desees")
.setContentInfo("Texto de informacion");
assert notificationManager != null;
notificationManager.notify(/*notification id*/1, notificationBuilder.build())
señale los puntos claves con comentarios, sin esas lineas podrás hacer lo que planteaste en tu pregunta.