Android battery temperature and voltage wrong values -
i have tested code. on 2 phones, work´s ok , give me right values. on tablet same code returns temperature value 0 , voltage value 3 (wrong values).
can give me understand ? each code try, return 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"); } };
probably devices return v, not mv. use this:
float v = (float) voltage; if (voltage > 12) v = (float) voltage / 1000; float t = (float) temp / 10;
Comments
Post a Comment