自己新建一个类 AutoBootReceiver
package com.demo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class AutoBootReceiver extends BroadcastReceiver {
public AutoBootReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
Intent intent2=new Intent(context,MainActivity.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
}
}
AndroidManifest.xml文件添加:
<!-- 开机自启动所需用的权限 -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name="com.demo.AutoBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
<category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>
</receiver>
原生Android 系统一定可以,但第三方的一些系统不一定能成功,像小米这些。可能启动方式不一样,有些是快速启动,不是完全的关闭系统,就会造成开机没有广播事件,那就监听不了开机了。而且有些第三方的系统由于安全的问题,默认禁止了后台启动app的权限
6 个回复
博美云言工
我也需要这个功能,一直没有找到合适的答案
DCloud_Android_ST
额 !没有能满足你需求的API 。你可以通过SDK集成通过原生来实现你的这需求
Android_磊子
没有相关api,这个功能需要你使用离线打包方式实现主体逻辑,5+进行页面展示。
Joshua
自己新建一个类 AutoBootReceiver
AndroidManifest.xml文件添加:
<!-- 开机自启动所需用的权限 -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name="com.demo.AutoBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
<category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>
</receiver>
原生Android 系统一定可以,但第三方的一些系统不一定能成功,像小米这些。可能启动方式不一样,有些是快速启动,不是完全的关闭系统,就会造成开机没有广播事件,那就监听不了开机了。而且有些第三方的系统由于安全的问题,默认禁止了后台启动app的权限
博美云言工
上面这个方法,我用本地打包实现了开机启动 APP,谢谢
小样儿king
怎么实现的? 能不能教教我?
2018-03-26 08:34
4***@qq.com
我也想学,还没有研究明白
2019-03-06 17:22
junhun
你是html5+写的吗?
2019-06-11 15:30
junhun - 90后
html5+的怎么解决?