我正在使用NotificationManager
構建器在我的應用程序中顯示警報。我知道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);
請參閱 –