Search code examples
androidandroid-intentbroadcastreceiver

AlarmManager / BroadcastReceiver does not work


I have this problem where AlarmManager does work properly or BroadcastReceiver does not receive notification. This problem happens when I test the app on on API 10 (2.3.7), however when I test it on API 14++, it works just fine. Below is the snippet of the code that calls the AlarmManager:

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent Notifyintent = new Intent(MainActivity.this, Notify.class);
PendingIntent Notifysender = PendingIntent.getBroadcast(getApplicationContext(),
0, Notifyintent, PendingIntent.FLAG_UPDATE_CURRENT);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Notifysender);

And this is the BroadcastReceiver class:

public class Notify extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("Notify","OnReceive");
    }
}

And the AndroidManifest.xml

    <receiver android:name=".Notify">
        <intent-filter>
            <action android:name="android.intent.action.NOTIFY"/>
        </intent-filter>
    </receiver>

If the code above is run on API 10 (2.3.7), the "Notify" log message will not appear, however if it's run on API 14++, the "Notify" log message appears just fine.

Thanks :)


Solution

  • Ooops, sorry, after trying it in different emulator (same API 10 2.3.7), it actually works just fine. So I think the problem is probably with the emulator. Thanks :)