package com.sunzee.receiver;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;

import com.sunzee.ui.activity.HomePageAActivity;

public class BootBroadcastReceiver extends BroadcastReceiver {
    static final String ACTION = "android.intent.action.BOOT_COMPLETED";

    @Override
    public void onReceive(Context context, Intent intent) {
        // 启动完成
        Intent i = new Intent(context, Alarmreceiver.class);
        i.setAction("arui.alarm.action");
        PendingIntent sender = PendingIntent.getBroadcast(context, 0,
                i, 0);
        long firstime = SystemClock.elapsedRealtime();
        AlarmManager am = (AlarmManager) context
                .getSystemService(Context.ALARM_SERVICE);

        // 10秒一个周期，不停的发送广播
        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstime,
                60 * 1000, sender);


        if (intent.getAction().equals(ACTION)) {
            Intent mainActivityIntent = new Intent(context, HomePageAActivity.class);  // 要启动的Activity
            mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(mainActivityIntent);
        }
    }
}
