private void sendBroadCastOrHeadlessTask(Intent intent) { if (mBindedCount > 0) { Log.w(TAG, "sendBroadcast,action:" + intent.getAction()); sendBroadcast(intent); } else { Log.w(TAG, "maybe start headless task,action:" + intent.getAction() ); // 在一些必要的点,发起headlessTask switch (intent.getAction()) { case ACTION_SERVICES_DISCOVERED: case ACTION_STATE_CHANGED: case ACTION_BOND_STATE_CHANGED: HeadlessJsTaskService.acquireWakeLockNow(this); Intent intent2 = new Intent(this, BleEventListener.class); intent2.putExtras(intent); intent2.putExtra(EXTRA_EVENT, intent.getAction()); startService(intent2); break; default: break; } } }