1

これは、次の Android 通知で使用されます。

http://www.vogella.com/articles/AndroidNotifications/article.html#notificationmanager_configure

// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
4

2 に答える 2

8

代入を伴うビット単位の OR。

int a = 6, b = 5;
a = a | b;
// is equivalent to
a |= b;

Android のようなシステムでは、多くの異なるブール プロパティを 1 つの整数値に圧縮することが理にかなっていることがよくあります。値は と組み合わせて|テストできます&

// invented constants for example
public static final int HAS_BORDER = 1;   // in binary: 0b00000001
public static final int HAS_FRAME = 2;    //            0b00000010
public static final int HAS_TITLE = 4;    //            0b00000100

public void exampleMethod() {
  int flags = 0;                          //    flags = 0b00000000
  flags |= HAS_BORDER;                    //            0b00000001
  flags |= HAS_TITLE;                     //            0b00000101

  if ((flags & HAS_BORDER) != 0) {
    // do x
  }

  if ((flags & HAS_TITLE) != 0) {
    // do y
  }
}
于 2013-07-27T23:30:50.883 に答える
4

と同じ:

noti.flags = noti.flags | Notification.FLAG_AUTO_CANCEL;

すべてのビットがORまとめられます。通常は、既存のフラグのセットにフラグを追加するNotification.FLAG_AUTO_CANCELのに適した方法です。これは、おそらくビットが 1 つだけ設定されているため、そのビットが でオンになるためですnoti.flags

于 2013-07-27T23:30:23.870 に答える