当我的重复警报广播被调用时,我正在尝试读取 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
. 我在这里缺少什么吗?我根据 android Google 页面添加了正确的权限,但这似乎没有帮助。