The provided code should be place inside Activity.
private BroadcastReceiver powerConnectReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent intent) {
boolean plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) > 0;
findViewById(R.id.map).setKeepScreenOn(plugged);
}
};
….
@Override
protected void onResume() {
registerReceiver(powerConnectReceiver, new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));
super.onResume();
}
@Override
protected void onPause() {
unregisterReceiver(powerConnectReceiver);
super.onPause();
}
No comments:
Post a Comment