在Android中,有没有办法让电池的电流? [英] In Android, is there a way to get the battery current?

查看:552
本文介绍了在Android中,有没有办法让电池的电流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在BatteryManager类不具备度量当前的: http://developer.android.com/reference/android/os/BatteryManager.html

The BatteryManager class doesn't have the metric for current: http://developer.android.com/reference/android/os/BatteryManager.html

然后我找到了这个帖子: <一href="http://stackoverflow.com/questions/2439619/getting-the-battery-current-values-for-the-android-phone">Getting对于Android手机的电​​池电流值 如此看来,笔者还发现,这是不可能从Linux条目得到这样的价值。

And then I have found this post: Getting the battery current values for the Android Phone It seems that the author also found it was not possible to get such value from the Linux entry.

我也下载了所谓的CurrentWidget到我的Nexus 7,对于当前值的小部件,它显示无数据。

I also downloaded the widget called CurrentWidget into my Nexus 7. For the current value, it shows "no data".

所以可能是一个电流传感器是必需的,以获得电流值和一些机器人系统根本没有这样的传感器。那么如何才能Android系统知道当前电池电量?也许它只是用电池的电压推断(电压放电过程中减少)?但是,那将是非常粗粒度。有人说,有用来估计没有电流值的Andr​​oid电池电量一些绝招(可能是基于电压?)。有没有参考?

So probably a current sensor is required to get the current value and some android systems just do not have such sensors. Then how can the android system know the current battery level? Maybe it will just use the voltage of the battery to infer that(voltage will decrease during the discharge)? But then it would be very coarse-grained. Someone says that there is some 'trick' used to estimate the battery level without current values in Android(probably based on Voltage?). Is there any reference?

PS:由于某些原因,我知道当前值可以记录在iphone 3GS

PS: for some reason, I know current value can be recorded on iphone 3GS

推荐答案

试试这个code,可将它有助于充分为您提供:

try this code,may be it would be help full for you:

private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
      @Override
      public void onReceive(Context arg0, Intent intent) {
        // TODO Auto-generated method stub
          //this will give you battery current status
        int level = intent.getIntExtra("level", 0);

        contentTxt.setText(String.valueOf(level) + "%");

        int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
        textView2.setText("status:"+status);
        boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                            status == BatteryManager.BATTERY_STATUS_FULL;
        textView3.setText("is Charging:"+isCharging);
        int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        textView4.setText("is Charge plug:"+chargePlug);
        boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;

        boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
        textView5.setText("USB Charging:"+usbCharge+" AC charging:"+acCharge);

      }
    };

在主类寄存器此使用:

 this.registerReceiver(this.mBatInfoReceiver, 
          new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

这篇关于在Android中,有没有办法让电池的电流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆