在AndroidManifest.xml中配置广播
<receiver android:name=".reveiver.AppReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
//自定义广播AppReceiver 并启动指定页面MainActivity
public class AppReceiver 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 intent= new Intent(context, MainActivity.class); //启动指定页面
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}
加上权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Android 开机启动app
最新推荐文章于 2024-06-19 10:54:20 发布