Reputation: 5895
I am following http://blog.blundell-apps.com/notification-for-a-user-chosen-time/ this post and I made my app. So I can set a alarm on a specific date and time. It works fine but once the phone is restarted then it will just go off. So I googled and come to know the BroadcastReceiver.
My receiver code is this
public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, NotifyService.class);
context.startService(serviceIntent);
}
}
}
I have this settings in my manifext
<service
android:name=".ScheduleService"
android:label="ScheduleService Manager" >
<action android:name="com.example.myapp.ScheduleService" />
</service>
<service
android:name=".NotifyService"
android:label="NotifyService Manager" >
<action android:name="com.example.myapp.NotifyService" />
</service>
<receiver
android:name="com.example.myapp.StartMyServiceAtBootReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
And I have this permission also
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
My BroadcastReceiver is starting after re-boot. But notifactions never shows. any idea why ?
Thanks
PS : Very very new to android :)
Upvotes: 1
Views: 471
Reputation: 12823
You actually have to set the alarm after the reboot. Simply setting up the boot receiver isn't enough.
You can see upcoming alarms from the adb shell like this:
adb shell dumpsys alarm
Upvotes: 1