Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android alarmManager setRepeating not triggering

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!

like image 635
that_guy Avatar asked Sep 05 '13 02:09

that_guy


3 Answers

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

like image 108
that_guy Avatar answered Oct 29 '22 13:10

that_guy


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>
like image 34
Peter Zhao Avatar answered Oct 29 '22 14:10

Peter Zhao


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" />
like image 31
jbr3zy Avatar answered Oct 29 '22 12:10

jbr3zy