I want to close my app when the battery level of the device gets low. I have added following codes in manifest.
<receiver android:name=".BatteryLevelReceiver"
<intent-filter>
<action android:name="android.intent.action.ACTION_BATTERY_LOW" />
<action android:name="android.intent.action.ACTION_BATTERY_OKAY" />
</intent-filter>
</receiver>
And following code in receiver
public class BatteryLevelReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "BAttery's dying!!", Toast.LENGTH_LONG).show();
Log.e("", "BATTERY LOW!!");
}
}
I am running the app on emulater and changing the battery level using telnet. It changes the battery level but not showing any toast or logs.
What am I missing? Any help is appreciated!