2010-11-08 7 views
5

Wie kann ich das tun? Meine aktuellen Code ist unten dargestellt:Android: Vibration in Übereinstimmung mit der Auswahl unter Sound-Einstellungen> Allgemein

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); 

Antwort

2

finden Sie in der Dokumentation für Notification#DEFAULT_ALL sowie DEFAULT_VIBRATE darunter. Geben Sie an, nicht zur Zeit, dass Sie die DEFAULT_VIBRATE Konfiguration (Ihre aktuellen Code wollen wählt nur DEFAULT_SOUND.

notification.defaults |= Notification.DEFAULT_VIBRATE; 

Wenn Sie die Geräte-Standardeinstellungen für beide Klang und Vibrieren verwenden möchten, können Sie das tun, bitweise mit OR:

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

Alternativ können Sie angeben, dass Sie alle die Standardeinstellungen für Benachrichtigungen verwenden möchten:

notification.defaults |= Notification.DEFAULT_ALL; 

Zusätzlich zu, dass, müssen Sie auch sicherstellen, dass Sie die VIBRATE permission in Ihrer AndroidManifest.xml-Datei angegeben haben:

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