开机自启有很多种办法,下面用广播的方式实现。 首先先创建广播,开机代码 public class BootCompleteReceiver extends BroadcastReceiver {
开机自启有很多种办法,下面用广播的方式实现。
首先先创建广播,开机代码
public class BootCompleteReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO: This method is called when the BroadcastReceiver is receiving// an Intent broadcast. if(Intent.ACTioN_BOOT_COMPLETED.equals(intent.getAction())) { Intent thisIntent = new Intent(context, MainActivity.class); thisIntent.setAction("Android.intent.action.MAIN"); thisIntent.addCateGory("android.intent.category.LAUNCHER"); thisIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(thisIntent); } }}
在清单文件里面注册,同时添加权限
<!-- .开机自启广播 --> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /><receiver android:name=".BootCompleteReceiver" android:enabled="true" android:exported="true"> <!-- 接收启动完成的广播 --> <intent-filter android:priority="1000"> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
完成
来源地址:https://blog.csdn.net/lanrenxiaowen/article/details/132108792
--结束END--
本文标题: Android如何实现开机自启
本文链接: https://www.lsjlt.com/news/402053.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0