public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context ctx, Intent intent) {
Log.i("BootReceiver__onReceive","onReceive");
String action="android.intent.action.MAIN";
String category="android.intent.category.LAUNCHER";
Intent myi=new Intent(ctx,IndexActivity.class);//跳转到应用的入口页面
myi.setAction(action);
myi.addCategory(category);
myi.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(myi);
public void onReceive(Context ctx, Intent intent) {
Log.i("BootReceiver__onReceive","onReceive");
String action="android.intent.action.MAIN";
String category="android.intent.category.LAUNCHER";
Intent myi=new Intent(ctx,IndexActivity.class);//跳转到应用的入口页面
myi.setAction(action);
myi.addCategory(category);
myi.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(myi);
}
}
}
在配置文件中添加权限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
在配置文件中添加:
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>