开机启动
platforms\android\src\com\bozhong\eap文件夹下
增加文件 BootBroadcastReceiver.java
//该类派生自BroadcastReceiver,覆载方法onReceive中,检测接收到的Intent是否符合BOOT_COMPLETED,如果符合,则启动MainActivity。
package
com.bozhong.eap;
import
android.content.BroadcastReceiver;
import
android.content.Context;
import
android.content.Intent;
public
class
BootBroadcastReceiver
extends
BroadcastReceiver {
static
final
String ACTION =
"android.intent.action.BOOT_COMPLETED"
;
@Override
public
void
onReceive(Context context, Intent intent) {
if
(intent.getAction().equals(ACTION)) {
Intent mainActivityIntent =
new
Intent(context, MainActivity.
class
);
// 要启动的Activity
mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mainActivityIntent);
}
}
}
package
com.bozhong.eap包名来自配置文件 显示名称为在安卓设备桌面上显示的名称 修改platforms\android\AndroidManifest.xml文件,
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> //增加权限
<application>节点下
//向系统注册了一个receiver,子节点intent-filter表示接收android.intent.action.BOOT_COMPLETED消息。
<receiver android:name=".BootBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>