This is my code:
public class PowerConnectionReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
intent = new Intent (context, MainActivity.class);
intent.putExtra("Charging", isCharging);
startActivity(intent);
}
}
I think it should work properly but I get an error at startActivity()
. It looks like it was undefinded. Does anybody know what's wrong with this?