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);
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.
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.
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
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.
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"/>
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"/>
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