2012-05-04 13 views
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); 
+0

答えて

6

これは自分でテストしただけで、振動や着信音は更新時にも消えます。

UPDATE:あなたはNotificationCompat.Builderかを使用している場合 だけ更新、Notification.BuilderあなたはsetOnlyAlertOnceのみ着信音を鳴らすように設定することができます/一回振動します。

0

NotificationCompat.Builder notificationBuilder =新しいNotificationCompat.Builder(MainActivity.this)

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

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

関連する問題