android 开机自动启动
来源:互联网 发布:微信企业宣传制作软件 编辑:程序博客网 时间:2024/04/29 19:16
</pre>初学 android 就是记录自己平时遇到的问题 及解决方案<p></p><p>现在公司需求是在机顶盒上 安装一个 应用 在开机的时候自动开启一个后台服务去做一些事情</p><p>用到了广播处理</p><p>先在Manifest文件中静态注册一个用来监听设备动态的广播</p><p></p><pre code_snippet_id="1585878" snippet_file_name="blog_20160223_2_6989421" name="code" class="java"> <!-- 系统启动完成后会调用 --> <receiver android:name="com.example.testghost.bootReceiver" android:enabled="true" android:priority="2147483647" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" />//开机广播 <action android:name="android.intent.action.SCREEN_ON" />//屏幕点亮 <action android:name="android.intent.action.SCREEN_OFF" />//屏幕熄灭 <action android:name="android.intent.action.USER_PRESENT" />//用户解锁 </intent-filter> </receiver>
然后实现这个广播
package com.example.testghost;import com.lidroid.xutils.util.LogUtils;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;import android.widget.Toast;public class bootReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {LogUtils.d("开及" + intent.getAction().toString());switch (intent.getAction()) {case Intent.ACTION_SCREEN_OFF:Toast.makeText(context, "锁屏", 1000).show();LogUtils.d("锁屏");break;case Intent.ACTION_SCREEN_ON:LogUtils.d("亮屏");Toast.makeText(context, "亮屏", 1000).show();break;case Intent.ACTION_USER_PRESENT:LogUtils.d("解锁");startService(context, intent);Toast.makeText(context, "用户解锁", 1000).show();break;case Intent.ACTION_BOOT_COMPLETED:LogUtils.d("开及");startService(context, intent);Toast.makeText(context, "用户开机", 1000).show();break;default:break;}}private void startService(Context context, Intent intent) {Log.d("DMCC", "收到广播 开启服务或者做一些其它的事情" + intent.getAction());}}
0 1
- android开机自动启动
- android 开机自动启动
- android 开机自动启动
- android 开机自动启动 | 开机自启
- android 设置开机自动启动
- Android 开机自动启动服务
- Android 开机自动启动应用
- Android应用 开机自动启动
- Android开机自动启动服务
- Android 开机自动启动服务
- android程序开机自动启动
- Android 4.0 开机自动启动
- android手机开机自动启动
- Android开机自动启动程序
- android开机自动启动程序
- Android App开机自动启动
- Android开机自动启动应用
- android APP开机自动启动
- JS之字符串相关
- iOS UIKit - UICollectionView
- JS之正则表达式相关
- Activity详解 (一) : Activity的创建与启动
- YV12 and NV12
- android 开机自动启动
- Caffe中Mnist的训练日志解读
- 关于Unity5版本动画系统中anystate跳转重复播放当前动画解决方案
- Maven学习 (五) 使用Nexus搭建Maven私服(LINUX)
- JS之Date对象
- iOS UIKit - UINavigationController
- HTML5移动开发技术要点总结及各事件含义
- JS之Math对象
- logo