7

ビルダーを使用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);
4

2 に答える 2

6

これを自分でテストしたところ、アップデートでもバイブレーション/着信音が鳴ります。

更新:使用している場合、NotificationCompat.Builderまたは着信音/バイブレーションを1回だけ鳴らすようにNotification.Builder設定できる場合は、更新のみ。setOnlyAlertOnce

于 2012-05-04T17:18:30.270 に答える
0

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);

于 2015-09-30T16:05:02.627 に答える