There are two problems here:
ρσѕρє K pointed to the first:
Initialize your context by adding a parameter to the CheckBatteryLevel () method or to the MyClass constructor
public class MyClass(Context ctx) {
context = ctx;
}
-, registerReceiver (..) , BroadcastReceiver. .
:
public class MyClassName {
BroadcastReceiver batteryInfoReceiverLevel;
public void CheckBatteryLevel(Context ctx) {
Log.d("App", "I'm in the CheckBatteryLevel");
batteryInfoReceiverLevel = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("Apps", "I'm in the onReceive");
int level= intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);
if(level <=100) {
} else if(level >=100) {
}
}
};
ctx.registerReceiver(batteryInfoReceiverLevel,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
}