更新通知振动/铃声

我正在使用NotificationManager构build器在我的应用程序中显示一个警报。 我知道notify方法的第一个参数是一个id和框架将更新通知,如果它已经可见,但如果我设置警报播放铃声或振动,如果警报是铃声/振动也会触发更新?

  NotificationCompat.Builder nb = new NotificationCompat.Builder(this); nb.setContentTitle("title"); nb.setContentText("message"); nb.setSmallIcon(getResources().getIdentifier("drawable/alert", null, packageName)); nb.setWhen(System.currentTimeMillis()); nb.setAutoCancel(true); nb.setTicker("message"); final Uri ringtone = Uri.parse(PreferenceManager.getDefaultSharedPreferences(this).getString("ringtone", getString(R.string.settings_default_ringtone))); nb.setDefaults(Notification.DEFAULT_VIBRATE); nb.setSound(ringtone); nb.setDefaults(Notification.DEFAULT_LIGHTS); NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); final Intent notificationIntent = new Intent(this, Main.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); nb.setContentIntent(contentIntent); Notification notification = nb.getNotification(); nm.notify(0, notification); 

Solutions Collecting From Web of "更新通知振动/铃声"

只是自己testing了这个,振动/铃声确实发生了,即使在更新。

更新:只是一个更新,如果你使用NotificationCompat.BuilderNotification.Builder你可以设置setOnlyAlertOnce只发出一次铃声/振动。

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MainActivity.this)

long [] v = {500,1000}; notificationBuilder.setVibrate(V);

Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); notificationBuilder.setSound(URI);