3

在 Axon ZTE 设备中,当我运行接收器时

private String isConnected(Context context) {
    String sRet = "";
    try {
        final Intent mIntent = context.getApplicationContext().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        int plugged = mIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);

        if ((plugged == BatteryManager.BATTERY_PLUGGED_AC) && ac_connected == false) {
            ac_connected = true;
            sRet = "AC";
        } else if (plugged == BatteryManager.BATTERY_PLUGGED_USB) {
            ac_connected = true;
            sRet = "USB";
            //Toast.makeText(ctx, "connected to usb ", Toast.LENGTH_LONG).show();

        } else {
            sRet = "NOT CHARGING";
        }
    } catch (Exception e) {
        sRet = "";
    }

    return sRet;

}

它总是返回“AC”而不是 USB,在其他设备中接收器运行良好。怎么会发生?

4

1 回答 1

0

我看到类似的行为。可能是设备制造商/ROM 报告不正确。除非您更喜欢挖掘设备日志,否则没什么可做的,您也许可以在终端中进行一些查询。

于 2020-08-27T11:13:34.757 回答