Android battery temperature and voltage wrong values

899 Views Asked by At

i have tested this code. On two phones, work´s ok and give me the right values. On a tablet the same code returns the temperature value as 0 and the voltage value as 3 (wrong values).

Can anybody give me a help understand this ? Each code i try, it return that values.

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

There are 1 best solutions below

0
On

Probably some devices return V, not mV. I use this:

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