Sir*_*ius 17 notifications android
我使用以下代码创建了一个创建通知的应用程序:
// 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);
Run Code Online (Sandbox Code Playgroud)
通知有效,并使用正确的铃声.
但是,即使正确激活了首选项并且正确设置了通知标志(我通过调试检查),通知也不会振动,也不会导致灯光被激活.
我本可以归咎于我的手机设置,但是使用通知的所有其他应用程序,如消息,gmail和其他正确使用所有这些功能.
愿有人知道我做错了吗?(我的手机是搭载Android 2.1的HTC Hero)
Pen*_*m10 28
添加清单文件的权限
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
Run Code Online (Sandbox Code Playgroud)
编辑
对于Lights尝试显式添加它们,默认灯可能配置为nolight
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23291 次 |
| 最近记录: |