android程序开机自启动
来源:互联网 发布:ih5页面制作软件 编辑:程序博客网 时间:2024/06/05 22:53
首先,在AndroidManifest.xml中申请权限,注册通知
<?xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidseekbartest"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiverandroid:name=".BootBroadcastReceive">
<intent-filter>
<actionandroid:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
<uses-permissionandroid:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
</manifest>
然后定义一个类继承自BroadcastReceiver,里边判断下如果是系统启动,那么就启动程序
package com.example.androidseekbartest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootBroadcastReceiveextends BroadcastReceiver {
staticfinal Stringaction_boot="android.intent.action.BOOT_COMPLETED";
@Override
publicvoid onReceive(Context context, Intent intent) {
if (intent.getAction().equals(action_boot)){
Intent intent2 = new Intent(context, MainActivity.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
}
}
}
MainActivity中不必做其他操作,由于我这个程序是跑在自定制的屏幕中的,没有一些什么手机管家,360啥的,能够启动。测试手机有这些软件貌似不行,会拦截。
这时,需要在手机管家中设置一下,设置成允许开机启动,在开机启动项中勾选你要运行的程序。
- Android开机自启动程序
- Android开机自启动程序
- Android 开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android 开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- Android开机自启动程序
- android程序开机自启动
- android 开机自启动程序1
- android 开机自启动程序2
- Android开机自启动程序 1
- android 开机自启动程序2
- 如何让APP字体不受手机设置的字体大小影响
- openstack 制作winserver2008_R2镜像 用cloudbase-init 实现第一次创建就注入密码(需登录)
- aaa
- ubuntu下安装Matlab
- Python 面向对象中的__init__、__new__以及super()
- android程序开机自启动
- 记录知乎上一位大神的言论
- 解决LOG4J:ERROR Failed to rename的问题
- SAP中ABAP编程有关生产订单的透明表有哪些
- 如何配置wordpress使用SMTP进行发邮件?
- POJ 1014 dividing
- Spring AOP 详解
- CSS3 边框/颜色/文字与字体/背景
- 图像特征提取(纹理特征)