Ich habe eine Anwendung erstellt, die Benachrichtigungen erstellt, mit dem folgenden Code:Wie kann ich Vibration und Lichter mithilfe der Android-Benachrichtigungen API aktivieren?
// notification
Notification notification = new Notification(R.drawable.notification_icon, title, System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// parameters
String ringtone = prefs.getString(context.getString(R.string.key_notifications_ringtone), "");
if (ringtone.length() > 0) {
notification.sound = Uri.parse(ringtone);
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
}
boolean useVibrator = prefs.getBoolean(context.getString(R.string.key_notifications_use_vibrator), false);
if (useVibrator) {
notification.defaults |= Notification.DEFAULT_VIBRATE;
}
boolean useLed = prefs.getBoolean(context.getString(R.string.key_notifications_use_led), false);
if (useLed) {
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
}
// alert
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification);
contentView.setImageViewResource(R.id.notification_icon, R.drawable.icon);
contentView.setTextViewText(R.id.notification_title, title);
contentView.setTextViewText(R.id.notification_text, text);
notification.contentView = contentView;
Intent notificationIntent = new Intent(context, MyActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notificationManager.notify(1, notification);
Die Benachrichtigung funktioniert und die richtigen Klingelton verwendet werden.
Obwohl die Einstellungen korrekt aktiviert sind und die Benachrichtigungsflags korrekt gesetzt sind (ich habe das Debuggen überprüft), vibriert die Benachrichtigung niemals und bewirkt nie, dass die Lichter aktiviert werden.
Ich hätte die Einstellungen meines Telefons verantwortlich gemacht, aber jede andere App, die Benachrichtigungen verwendet, wie Messaging, Google Mail und andere, verwenden alle diese Funktionen korrekt.
Darf jemand wissen, was ich falsch gemacht habe? (Mein Telefon ist ein HTC Hero mit Android 2,1)
Haben Sie die Vibrationserlaubnis? – Sephy
Ich testete Ihren Code auf meinem Nexus One, mit der Erlaubnis, und ich bekomme die Vibration, aber nicht die LED ... immer noch graben – Sephy
gleiche Sache, ich hatte die Schwingung Erlaubnis verpasst, und jetzt dieser Teil funktioniert. – SirDarius