Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vibrate and Sound defaults on notification

Tags:

android

I'm trying to get a default vibrate and sound alert when my notification comes in, but so far no luck. I imagine it's something to do with the way I set the defaults, but I'm unsure of how to fix it. Any thoughts?

public void connectedNotify() {     Integer mId = 0;     NotificationCompat.Builder mBuilder =             new NotificationCompat.Builder(this)             .setSmallIcon(R.drawable.ic_notify)             .setContentTitle("Device Connected")             .setContentText("Click to monitor");      Intent resultIntent = new Intent(this, MainActivity.class);      TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);     stackBuilder.addParentStack(MainActivity.class);     stackBuilder.addNextIntent(resultIntent);     PendingIntent resultPendingIntent =                PendingIntent.getActivity(getApplicationContext(),            0,            resultIntent,             PendingIntent.FLAG_UPDATE_CURRENT);     mBuilder.setContentIntent(resultPendingIntent);     mBuilder.setOngoing(true);     Notification note = mBuilder.build();     note.defaults |= Notification.DEFAULT_VIBRATE;     note.defaults |= Notification.DEFAULT_SOUND;     NotificationManager mNotificationManager =         (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);     mNotificationManager.notify(mId, note);  } 
like image 504
Dave Moore Avatar asked Aug 15 '13 13:08

Dave Moore


People also ask

What is a default notification sound?

This option allows you to set the default ringtone to be played when you receive a text message or other notification for which you have enabled sounds, such as an incoming email.

Why can't I turn off vibrate for notifications?

Go to Settings > Sound & Vibration and toggle the settings to switch vibration off. You can also go to Settings > Manage Notifications or Apps & Notifications to adjust vibration settings for individual apps. Adjusting vibration settings provides a more personalized experience.


1 Answers

Some dummy codes might help you.

   private static NotificationCompat.Builder buildNotificationCommon(Context _context, .....) {             NotificationCompat.Builder builder = new NotificationCompat.Builder(_context)             .setWhen(System.currentTimeMillis()).......;      //Vibration         builder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });       //LED         builder.setLights(Color.RED, 3000, 3000);       //Ton         builder.setSound(Uri.parse("uri://sadfasdfasdf.mp3"));      return builder;    } 

Add below permission for Vibration in AndroidManifest.xml file

<uses-permission android:name="android.permission.VIBRATE" /> 
like image 69
TeeTracker Avatar answered Nov 07 '22 21:11

TeeTracker