2012-05-04 103 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.BuilderNotification.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);