我的一些用户在Android (他们的车里)上安装了头单元设备,当然,这样的设备没有电池,下一个代码返回0
val batteryLevel = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
下一个方法将返回false
val status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1)
val statusCharging = status == BatteryManager.BATTERY_STATUS_CHARGING
我有一个录像
当我的重复警报广播被调用时,我正在尝试读取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;
我正在尝试在android中做电池充电日志,它工作得很好。但问题是我无法检测电池电量和充电器的状态。对于你的信息,我是一个使用android的初学者,希望有人能帮助我的代码。
public class ListViewA extends Activity {
/**Called when the activity is first created.*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentV
我一直在尝试收听电池BroadCast事件。已插入/未插入。
public class BatteryReceiver extends BroadcastReceiver {
public BatteryReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
if(status == Bat
@Override
public void onReceive(Context context, Intent intent) {
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
BatteryManager.BATTERY_STATUS_UNKNOWN);
if (status == BatteryManager.BATTERY_STATUS_CHARGING
|| status == BatteryManager.BATTERY_STATUS_FULL)
Toast.
我正在使用BroadcastReceiver来监控电池电量。我引用了,我的代码是
public class PowerConnectionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY
我正在尝试按照上的指导从我的应用程序中获取电池信息
这是用来检查电池电量的方法:
public void sendBatteryInfoMessage(){
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = c.registerReceiver(null, iFilter);
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
我正在尝试获取广播接收器类中的电池状态和电量,然后将其显示在通知中。
public class BatteryBroadcasts extends BroadcastReceiver {
private static final int NOTIFICATION_ID = 234234;
@Override
public void onReceive(Context context, Intent intent) {
String notiText;
NotificationCompat.Builder mBuilder = new NotificationCompat.B
嗨,我有这个服务在后台运行一个通知:
public class service extends Service {
NotificationManager mNotificationManager;
public SharedPreferences preferences;
public SharedPreferences myPref;
// Notifications//
private static final int SIMPLE_NOTIFICATION_ID = 1;
private static final String PREFS
我正在试图监视我的电池状态,但我一直从侦听器获取默认值,这是我的接收类:
public class BatteryIndicatorListener extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Log.d("battery status", "changed");
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
我试着做两个祝酒词:一个是当设备充电时,另一个是在没有充电的时候。但接收者表现得很疯狂,发出了许多祝酒词,并破坏了应用程序。我找不到问题。索尼克斯!这是主要活动的接受者:
public class PowerConnectionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);