vbm*_*n11 2 java notifications android
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);
Run Code Online (Sandbox Code Playgroud)
这个代码在我的Android应用程序中,我收到通知但没有声音或振动.
我已经在多部手机上进行了测试,声音和振动都在设置中打开和关闭.我也确定我要求在android清单中使用振动许可但我仍然只收到通知......
我也尝试过:
notification.defaults = Notification.DEFAULT_ALL;
Run Code Online (Sandbox Code Playgroud)
和
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
Run Code Online (Sandbox Code Playgroud)
如何在通知中获得声音和振动?
归档时间: |
|
查看次数: |
6381 次 |
最近记录: |