Android: Vibrate as selected in Sound Settings> General

How can i do this? My current code is shown below:

final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.stat_sys_warning, System.currentTimeMillis());    
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(Intent.ACTION_MAIN, Uri.EMPTY, context, Activity....class).putExtra(...);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, text, contentIntent);
manager.notify(1, notification);
+5
source share
1 answer

See the documentation for Notice # DEFAULT_ALL , as well DEFAULT_VIBRATEbelow. You are not currently specifying what you want to configure DEFAULT_VIBRATE(your current code selects DEFAULT_SOUND.

notification.defaults |= Notification.DEFAULT_VIBRATE;

If you want to use the default device settings for sound and Vibration, you can do this with bitwise OR:

notification.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;

Alternatively, you can specify that you want to use all the default notification settings:

notification.defaults |= Notification.DEFAULT_ALL;

, , VIBRATE , AndroidManifest.xml:

<uses-permission android:name="android.permission.VIBRATE" />
+2

All Articles