android开机自启广播无效果的曲线解决方案
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="where.com.whereareyou">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-sdk android:minSdkVersion="7" android:sharedUserId="android.uid.system" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.Holo.NoActionBar"> <activity android:name="where.com.whereareyou.MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name="where.com.whereareyou.BootBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.media.AUDIO_BECOMING_NOISY" /> </intent-filter> </receiver> <service android:name=".MyService"/> </application></manifest>
MyService
package where.com.whereareyou;
import android.app.Service;import android.content.Intent;import android.os.IBinder;import android.util.Log;
/** * Created by Administrator on 2015-10-4. */public class MyService extends Service { public final static String TAG = "MyService";
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.e(TAG,"onStartCommand"); return START_NOT_STICKY; }
@Override public void onDestroy() { super.onDestroy(); Log.e(TAG,"onDestroy"); }
@Override public IBinder onBind(Intent intent) { return null; }}
BootBroadcastReceiver
package where.com.whereareyou;
import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;
/** * Created by Administrator on 2015-10-4. */public class BootBroadcastReceiver extends BroadcastReceiver { static final String TAG = "BootBroadcastReceiver";
@Override public void onReceive(Context context, Intent intent) { Log.e(TAG, "BootBroadcastReceiver onReceive"); if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) || android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) { Log.e(TAG, "action=" + intent.getAction()); Intent ootStartIntent = new Intent(context, MyService.class); context.startService(ootStartIntent); } }
}
如代码所示,Intent.ACTION_BOOT_COMPLETED表示boot启动完毕后,系统会发送一个广播过来,理论上确实可以接收到,大部分手机估计也都是可以的,但是就是有那么些手机rom被改得不可思议,非要加上个android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY才可以在开机的时候让系统执行Intent.ACTION_BOOT_COMPLETED广播的发送,根据LOG可以看出,以OPPO1107为例,系统是先发送了ACTION_AUDIO_BECOMING_NOISY后发送了ACTION_BOOT_COMPLETED,仅以此博,做个纪念
android开机自启广播无效果的曲线解决方案相关推荐
- Android开机自启监听网络改变源码
先看下主页面代码 mainactivity.java package cn.xiayiye.networkchange;import android.app.Activity; import andr ...
- android开机自启
1.监控RECEIVE_BOOT_COMPLETED,即开机自启动事件AndroidManifest.xml 设置开机启动权限以及相应的receiver 2.监控sd卡的mount事件,开机的时候一般 ...
- 关于Ubuntu启动activeMq无效果的错误解决方案
解压tar包到 /opt路径下: 开启服务,显示开启,但 http://127.0.0.1:8161/admin/ -->404 寻其原因: /opt/activemq/bin/active ...
- Android开机自启自动轮播图片或自动轮播视频APP
之前实验室有很多展示的设备,每次上电之后还需要单个点击打开每个展示设备开发好的APP,因为每个设备没有触屏,需要抱着电脑去实验室 挨个连接USB 使用scrcpy 挨个机器点开,每次搞完都是一身汗,作 ...
- Span元素的 width属性 无效果原因及解决方案
先运行下程序看下: <span style='background-color:#336699;width:300px;'>123</span> 输出:123 可以看到 spa ...
- android 关机消息广播,Android开机、关机播音监听
Android开机.关机广播监听 一.开机广播的监听 1.在AndroidManifest.xml文件注册接收开机广播 2.在BroadcastReceiver里执行要做的事情 public clas ...
- Android 应用开机自启和无需权限开启悬浮框
开机自启主要自定义广播接收类,且需要在清单文件中注册,不要在代码中动态注册. <uses-permission android:name="android.permission.REC ...
- android 动态创建view,react-native动态创建Android View 无效果
问题描述 react-native动态创建Android View 无效果,我想在react-native里面直接点击函数进行创建,也就是通过module中的方法创建View 问题出现的环境背景及自己 ...
- android电池充电动画,Android 开机充电图标和充电动画效果
首先驱动需要先获取到2个power supply kernel\msm-3.18\drivers\usb\phy\phy-msm-usb.c motg->usb_psy.name = " ...
最新文章
- java arrays.sort() c_正面刚算法-Java中Arrays.sort()(一)
- 在CheckBox中,仅仅允许选择一项
- centos7 harbor 单机搭建
- 求封闭曲线面积vc代码_圆锥曲线综合5个类型,逐一突破
- C语言程序练习-L1-032 Left-pad (20分)
- 玩转Nacos参数配置!多图勿点
- SpringBoot集成Actuator健康指示器health
- linux 查看 pppoe dns,Ubuntu 7.04中ADSL拨号上网及DNS设置
- Atitit vscode 调试php vscode使用法 目录 1. 直接debug没反应,或者打开扩展列表	1 2. 调试配置法	1 2.1. Debug》》Add cfg php	1 2.2.
- 基于流程管理的企业风险管理模式
- cad黑色背景变成白色_CAD操作很难记?记住了又易混淆?那就看这里!
- python爬取链家租房信息_爬取链家租房信息数据分析
- 新版抖音二维码生成工具源码+实测可用
- android开发找不到模拟器(PANIC: Could not open:)解决办法
- python 人民币兑美元汇率_人民币汇率转换(python人民币和美元转换)
- linux服务器挂掉之后
- 音频加速 foobar_如何使用Foobar2000将音频CD翻录到FLAC
- 常见路由协议总览以及路由协议分类方式
- 思科光交MDS9710绑定WWN并激活新的wwn
- CentOS搭建SonarQube8.3