I am trying to setup an alarm at a specified time, but it is not being caught in my reciver.
Setup:
Intent intent = new Intent(this, ActionReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Calendar current = Calendar.getInstance();
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, (current.getTimeInMillis() + 60000),3600000, pendingIntent);
Here is my reciver:
public class ActionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras(); //breakpoint here that doesn't get triggered
}
}
I have put these values in my manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<receiver android:name="com.project.ActionReceiver" android:enabled="true" />
Not sure what is wrong... thanks!
Finally got the receiver to fire! I added the following code to my manifest:
<receiver
android:name="com.project.ActionReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.project.ActionSetter" >
</action>
</intent-filter>
</receiver>
Found here with details: https://stackoverflow.com/a/16119351/1174574
The name of receiver in your manifest should be class name, such as:
<receiver android:name="com.project.ActionReceiver">
BTW, set an action is a better practice.
Intent intent = new Intent(this, ActionReceiver.class);
intent.setAction("com.project.action.ALERM");
And in the manifest
<receiver android:name="com.project.ActionReceiver">
<intent-filter>
<action android:name="com.project.action.ALERM"/>
</intent-filter>
</receiver>
Try changing the android:name
attribute of your receiver
to the fully qualified class name of your ActionReceiver
. Something like:
<receiver android:name="com.project.ActionReceiver" android:enabled="true" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With