Reputation: 187
Can someone please help me out with this. I want to get notified when my phone battery becomes low. My androidManifest file looks like this:
<receiver android:name="com.dac.BatteryChangedBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BATTERY_LOW" />
</intent-filter></receiver>
and my receiver file is:
public class BatteryChangedBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
if(Intent.ACTION_BATTERY_LOW.equalsIgnoreCase(intentAction))
Toast.makeText(context, "Battery Power Low or Okay", Toast.LENGTH_LONG).show();
}
}
I am changing the battery level using the telnet command. My phone battery does change but I do not get any toast message. I have even tried registering the receiver using code
Upvotes: 0
Views: 758
Reputation: 9434
The "com. in the android:name looks questionable. If BatteryChangedBroadcastReceiver is in the default package for the application the name should begin with the dot. If not, it should be fully qualified. If you are writing your code in package com -- well -- don't do that, it hurts.
Upvotes: 0
Reputation: 36205
You probably need to add the following permission to your manifest file.
<uses-permission android:name="android.permission.BATTERY_STATS" />
Upvotes: 1