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