码迷,mamicode.com
首页 > 其他好文 > 详细

开机启动广播

时间:2016-04-26 09:40:57      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:

BootReceiver.java

package com.hanqi.testbr;

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

public class BootReceiver extends BroadcastReceiver {
    public BootReceiver() {
        Log.e("ATG","构造开机完成广播接收器");
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("ATG","广播接收器自动启动Service");
        //启动服务
        context.startService(new Intent(context,BootService.class));
    }
}

BootService.java

package com.hanqi.testbr;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;

/**
 * Created by Administrator on 2016/4/25.
 */
public class BootService extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.e("ATG", "服务自动启动的");
    }
}

 

开机启动广播

标签:

原文地址:http://www.cnblogs.com/cuikang/p/5433693.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!