Android电池温度和电压错误值

时间:2014-11-19 11:59:01

标签: android battery temperature

我已经测试了这段代码。在两部手机上,工作正常,并给我正确的价值观。在平板电脑上,相同的代码将温度值返回为0,将电压值返回为3(错误的值)。

任何人都可以帮我理解这个吗?我尝试的每个代码,它返回的值。

Thank's。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub      
     View rootView = inflater.inflate(R.layout.battery_fragment1, container, false);        





    rootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT ));   






    getActivity().registerReceiver(mBatInfoReceiver, new IntentFilter(

            Intent.ACTION_BATTERY_CHANGED));

    BatTemp=(TextView)rootView.findViewById(R.id.batteryStatus);



    return rootView;
}

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {

    @Override

    public void onReceive(Context c, Intent intent) {



        level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);

        health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);

 //       icon_small = intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL, 0);

        plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);

        present = intent.getExtras().getBoolean(

                BatteryManager.EXTRA_PRESENT);

        scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);

        status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);

        technology = intent.getExtras().getString(

                BatteryManager.EXTRA_TECHNOLOGY);

        temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,

                -1);

        voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0);



   //     pb.setProgress(level);



        BatTemp.setText("Level: " + level + "\n\n" + "Health: " + health + "\n\n"

                + "\n\n" +



                "Plugged: " + plugged + "\n\n" + "Present: " + present + "\n\n"

                + "Scale: " + scale + "\n\n" + "Status: " + status + "\n\n"

                + "Technology: " + technology + "\n\n" + "Temperature: "

                + temperature + "\n\n" + "Voltage: " + voltage + "\n\n");



    }

};

1 个答案:

答案 0 :(得分:0)

可能有些设备返回V,而不是mV。 我用这个:

    float v = (float) voltage;
    if (voltage > 12)
        v = (float) voltage / 1000;
    float t = (float) temp / 10;