2012-03-23 26 views

答えて

2

Notificationクラスには、参照を保持するだけで直接変更できる多くのパブリックフィールドがあります。それの他の特性は、明らかに変更されるようには設計されていません(通知が大幅に変更された場合、ユーザーを混乱させる可能性があります)。

推奨されない方法を使用するか、通知を再構築して新しいものを表示する必要があります。

http://developer.android.com/reference/android/app/Notification.html

0

はい、あなたは、既存の通知の内容を更新することができます。しかし、同じ通知IDを使って同様に再構築しました。また、関連するフラグをすべて削除し、優先順位をデフォルトに設定します。

同じ通知IDにより、新しい通知IDが作成されます。通知はすでに開始されているため、フラグは振動していて、ライトが適切ではない可能性があります。プライオリティはデフォルトに設定されているため、通知トレイ内の通知の位置は変更されません。優先度を高く設定すると、トレイの上部に移動します。

ここに実装方法を示します。 *関連コードを追加しました。

public void showNotification(String action){ 
    RemoteViews views = new RemoteViews(getPackageName(), 
      R.layout.status_bar); 
    Notification status; 
    if(action.equals("play")){ 
     views.setImageViewResource(R.id.status_bar_play, R.drawable.play); 
    status = notificationBuilder 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setPriority(Notification.PRIORITY_HIGH) 
      .setContentIntent(pendingIntent) 
      .setContent(views) 
      .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS) 
      .build(); 
    } else { 
     views.setImageViewResource(R.id.status_bar_play, R.drawable.pause); 
     status = notificationBuilder 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setPriority(Notification.PRIORITY_DEFAULT) 
      .setContentIntent(pendingIntent) 
      .setContent(views) 
      .build(); 
    } 
    NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(Constants.NOTIFICATION_ID, status); 
} 

このようにして、既存の通知の内容を変更することができます。

関連する問題