Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notification not making sound or vibration?

I am making a program and I want the app to make a notification. When the notification goes off then only the ticker text is displayed. No sound or vibration or light is accompanied with it.

Here is an example of my code:

int icon = R.drawable.icon;  
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

Context context = getApplicationContext();      

CharSequence contentTitle = "My notification";  
CharSequence contentText = "Countdown Complete!";

Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new Notification(icon, myCountDown.getName() + " is completed!", System.currentTimeMillis());

long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
notificationManager.notify(myCountDown.getId(), notification);
like image 232
Tj5 Avatar asked Jan 12 '12 22:01

Tj5


People also ask

Why are my notification sounds not working on my phone?

Another possible cause for your notification sounds not working can be a Do Not Disturb option. When enabled, it will give no reminders for incoming calls and notifications. Depending on your phone it can be located either in Notifications or Sound & vibration in your Settings.

Why are my incoming text messages no longer triggering audio notifications?

After getting a brand new phone (Pixel 4a, with Android 10), incoming text messages / SMS no longer triggered an audible notification sound. Even after tweaking global notifications settings and setting ringer volume to maximum, no text messages could trigger an audio alert.

How to enable or disable messenger notifications & sounds on Android?

Open the Messenger app and tap on your profile picture visible on the top-left corner. Find out the Notifications & sounds settings and tap on it. Make sure these two following settings are enabled. If not, toggle the respective buttons to turn on notification sound and preview. 2. Disable Do Not Disturb

Why is there no sound coming from my phone when texting?

Even after tweaking global notifications settings and setting ringer volume to maximum, no text messages could trigger an audio alert. There would be a visual notification shown, but no sound. Searching across the internet, it is clear this is not an isolated incident.


2 Answers

To add notification light you need to add this(notice the .flags, not .defaults):

notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.ledARGB=0xffffffff; //color, in this case, white
notification.ledOnMS=1000; //light on in milliseconds
notification.ledOffMS=4000; //light off in milliseconds

For default sound:

notification.defaults |= Notification.DEFAULT_SOUND;

For default vibration pattern:

notification.defaults |= Notification.DEFAULT_VIBRATE;

For vibration, as Dean Thomas mentioned, you'll need a permission <uses-permission android:name="android.permission.VIBRATE"/>

like image 54
Anton Cherkashyn Avatar answered Nov 14 '22 22:11

Anton Cherkashyn


To make the LED work, you need to tell it what to do.

   notification.ledOnMS = 1000; //Be on for a second
   notification.ledOffMS = 1000; //Be off for a second
   notification.ledARGB = Color.GREEN; //What colour should the LED be?

To make the vibrate work, you need permission added to your Manifest

<uses-permission android:name="android.permission.VIBRATE"/>
like image 28
Dean Thomas Avatar answered Nov 14 '22 23:11

Dean Thomas