package com.wdkl.ncs.s433.transbox.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;

import com.wdkl.ncs.s433.transbox.MainActivity;

public class WdBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, Intent intent) {
        if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
            Log.d("wdBoot", "收到开机广播，启动app");
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    startHome(context);
                }
            }, 5000L);
        }
    }

    private void startHome(Context context) {
        Log.d("wdBoot", "start home activity");
        Intent startIntent= new Intent(context, MainActivity.class);
        startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(startIntent);
    }
}
