Android中广播优先级设置

Android广播优先级设置

由于开机时,接收到的广播的时间比较后,导致有些操作没来得及做
这时可以使用setPriority来提高当前Intent的优先级,使得可以在广播发出时,马上就可以收到了。优先级权限设置成IntentFilter.SYSTEM_HIGH_PRIORITY即可。

范例如下:

IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);

filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);

mContext.registerReceiver(
    new BroadcastReceiver() {
       @Override
          public void onReceive(Context context, Intent intent) {
              String action = intent.getAction();
              if (action.equals(Intent.ACTION_SCREEN_ON)) {
                  handleScreenStateChanged();
          }
      }, filter);

猜你喜欢

转载自blog.csdn.net/gh201030460222/article/details/80629557