我怎样才能使振动和使用Android通知API灯?能使、通知、Android、API

由网友(江河没有风)分享简介:我已经创建,创建通知,使用下面的code的应用程序:I have created an application that creates notifications, using the following code:// notificationNotification notification = new N...

我已经创建,创建通知,使用下面的code的应用程序:

I have created an application that creates notifications, using the following code:

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

的通知的工作原理,以及正确的铃声使用。

The notification works, and the correct ringtone is used.

然而,即使preferences被正确激活和通知标记是否正确设置(Ⅰ检查调试),通知决不振动,并不会导致灯被激活。

However, even though the preferences are correctly activated and notification flags are correctly set (I checked by debugging), the notification never vibrates and never cause the lights to be activated.

我会责怪我的电话的设置,但使用所有其他应用程序的通知,如短信,Gmail和其他人正确使用所有这些功能。

I would have blamed my phone's settings, but every other app using notifications, like messaging, gmail, and others correctly use all these features.

五月有人知道我做错了什么? (我的手机是HTC Hero采用了Android 2.1)

May someone know what I did wrong ? (my phone is a HTC Hero with Android 2.1)

推荐答案

添加权限您的清单文件

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

修改

有关灯尽量明确地将它们添加,默认光可能会被配置为nolight

For Lights try adding them explicitly, the Default light might be configured to be nolight

notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
阅读全文

相关推荐

最新文章