【发布时间】:2012-01-26 22:32:46
【问题描述】:
int icon = R.drawable.icon;
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Countdown Complete!";
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent();
Notification notification = new Notification(icon, "is completed!", System.currentTimeMillis());
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notificationManager.notify(myCountDown.getId(), notification);
此代码在我的 android 应用程序中,我收到通知但没有声音或振动。
我已经在多部手机上进行了测试,所有手机都在设置中打开并打开了声音和振动。我还确保我要求在 android 清单中使用振动权限,但我仍然只收到通知...
我也试过了:
notification.defaults = Notification.DEFAULT_ALL;
和
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
如何在通知中获得声音和振动?
【问题讨论】:
标签: java android notifications