赞
踩
第一步:在AndroidManifest.xml清单文件中申请下面的权限
<!--开机自启动广播权限-->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
第二步:实现 BroadcastReceiver接口
package com.andy.leo.broadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class AutoStartAppBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent intent=new Intent(context,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
第三步:在AndroidManifest.xml清单文件中静态注册广播接收器的配置
<receiver android:name="com.andy.leo.broadcast.AutoStartAppBroadcastReceiver ">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
结束!!!
程序是有灵魂的,值得没有灵性的我用一生去学习!!!
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。