Android启动时,会发出一个系统广播 ACTION_BOOT_COMPLETED,它的字符串常量表示为 “android.intent.action.BOOT_COMPLETED”

开机自启动程序,只需要“捕捉”到这个消息再启动你的程序即可,我们要做的是接收这个消息,并实现一个BroadcastReceiver。

1 :xml 配置

在AndroidManifest.xml中Application节点内,添加自定义的广播类:

         <receiver android:name=".BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>

在AndroidManifest.xml中manifest节点内,添加开机启动权限:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

2: 自定义广播类 BootReceiver

 public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { // boot
Intent intent2 = new Intent(context, MainActivity.class);
// intent2.setAction("android.intent.action.MAIN");
// intent2.addCategory("android.intent.category.LAUNCHER");
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
}
}
}

3 :Activity

 public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Android 开机自启动应用的更多相关文章

  1. Android开机自启动程序

    背景知识:当Android启动时,会发出一个系统广播,内容为ACTION_BOOT_COMPLETED,它的字符串常量表示为 android.intent.action.BOOT_COMPLETED. ...

  2. Android 开机自启动

    首先实现开机自启动: 第一步创建一个广播接收者,如MyBootBroadcastReceiver.java package com.example; import android.content.Br ...

  3. android 开机自启动实现

    App的开机自启动可以通过注册广播接收器接收开机广播来实现,具体步骤如下: 1.创建 BroadcastReceiver 的派生类,并重写 onReceive() 函数: /** * Created ...

  4. Android——开机自启动app

    android在开机完成后会发送一个android.intent.action.BOOT_COMPLETED的广播,告诉系统内app们已经开机. 我们可以在需要开机自启动的app中定义一个广播接收器, ...

  5. Android::开机自启动C程序【转】

    本文转载自:http://blog.csdn.net/Kaiwii/article/details/7681736 之前一篇博文介绍了shell脚本文件的开机启动,地址是http://blog.chi ...

  6. android 开机自启动的几种方法,监听不到RECEIVE_BOOT_COMPLETED的处理办法

    第一种:  监控RECEIVE_BOOT_COMPLETED,即开机启动事件 另外一种: 监控sd卡mount事件  开机总会扫描sd卡吧? 监控sd卡事件也有类似开机启动效果.特别app安装在sd卡 ...

  7. Android开机自启动

    1.原理 当Android启动时,会发出一个系统广播,内容为ACTION_BOOT_COMPLETED,它的字符串常量表示为 android.intent.action.BOOT_COMPLETED. ...

  8. android开机自启动广播

    权限<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>     &l ...

  9. Android浮动小球与开机自启动

    看着手机上的360浮动小球,不评价其具体的功能与实用性,至少在UI设计与交互方面是个不小的创新. 如图片左上角所示,球中还会显示当前手机的运行状况,向下拉动还会有弹射来达到加速.清理等目的. 那好,先 ...

随机推荐

  1. 判断sqlserver临时表等临时资源是否存在

    if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TEMP'))  drop table #TEMP

  2. Telnet端口测试

    $IP ="220.181.111.142"$Port ="801" Function Port-Test ($IP,$Port){ $Timeout = 10 ...

  3. hdu 5586 Sum 最大子段和

    Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5586 Desc ...

  4. Solaris 安装JDK

    http://blog.csdn.net/cymm_liu/article/details/46966237  整理自前辈的博客:http://segmentfault.com/a/119000000 ...

  5. Gradient Boost Decision Tree(&Treelink)

    http://www.cnblogs.com/joneswood/archive/2012/03/04/2379615.html 1.      什么是Treelink Treelink是阿里集团内部 ...

  6. 为laravel分页样式制定class

    做的项目有一个上翻页和下翻页,使用了框架提供的

  7. Cloudera集群中提交Spark任务出现java.lang.NoSuchMethodError: org.apache.hadoop.hbase.HTableDescriptor.addFamily错误解决

    Cloudera及相关的组件版本 Cloudera: 5.7.0 Hbase: 1.20 Hadoop: 2.6.0 ZooKeeper: 3.4.5 就算是引用了相应的组件依赖,依然是报一样的错误! ...

  8. Sorting It All Out

    Description An ascending sorted sequence of distinct values is one in which some form of a less-than ...

  9. python(1) - 字符串

    前面说过了,字符串也是一种数据类型,但字符串有一个特殊的问题,就是编码. 因为计算机是美国人发明的,所以最早只有127个字符被编码到计算机里,就是大小写英文字母,数字和一些符号,这个编码表被称为ASC ...

  10. [转]HTML accesskey 属性

    本文转自:http://www.dreamdu.com/xhtml/attribute_accesskey/ 17.2. HTML accesskey 属性 accesskey 属性  --  代表链 ...