1

我有一个正确broadcastreceiver接收事件的android.intent.action.ACTION_POWER_CONNECTED。然后我使用此代码来检测设备是否已连接到墙壁socket (AC)USB无线充电或无线充电:

  IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
  Intent batteryStatus = Contexto.registerReceiver(null, ifilter);
  int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
  boolean bUsb = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
  boolean bAC = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
  boolean bWireless = chargePlug == BatteryManager.BATTERY_PLUGGED_WIRELESS;   

它可以完美地在一台设备上运行。但在另一台设备中,它总是说它只是在USB充电,即使插在墙上也是如此。知道为什么会这样吗?

4

0 回答 0