简体   繁体   中英

Android - start AlarmManager after reboot

AlarmManeger doesn't start after reboot but it should. How can I do it? AndroidManifest:

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <receiver android:name=".AlarmEngine.AlarmManagerHelper" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"></action>
        </intent-filter>
    </receiver>

BroadcastReceiver:

@Override
    public void onReceive(Context context, Intent intent)
    {
        setAlarms(context);
    }

public static void setAlarms(Context context)
{
    cancelAlarms(context);
    AlarmDBHelper dbHelper = new AlarmDBHelper(context);
    List<AlarmModel> alarms =  dbHelper.getAlarms();

        for (AlarmModel alarm : alarms)
        {
                PendingIntent pIntent = createPendingIntent(context, alarm);
...
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pIntent);

I fixed it moved app to the phone's memory.

I replace this:

android:installLocation="preferExternal" >

On this:

android:installLocation="internalOnly" >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM