我想在重复的闹钟广播器被调用时读取Android电池的状态,我的设置如下:
public class RepeatingAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
// Acquire the make of the device
final String PhoneModel = android.os.Build.MODEL;
final String AndroidVersion = android.os.Build.VERSION.RELEASE;
// Grab the battery information
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
final float batteryPct = level / (float)scale;
}
}
但我不明白为什么它返回了batteryPct = 1
。这里有什么我漏掉的吗?我已根据安卓谷歌页面添加了正确的权限,但似乎没有帮助。