IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> Android9.0 监听开机广播 -> 正文阅读

[移动开发]Android9.0 监听开机广播

软件版本:9.0Go

硬件平台:MTK8175

近日,需要在如上平台监听开机广播,Android高版本限制了开机广播监听的权限,这次我添加到了SystemUI中,方法如下:

进入SystemUI源码目录,添加src/com/android/systemui/media/GeiniBroadcastReceiver.java

类,内容如下:

/*

* Copyright (C) 2010 The Android Open Source Project

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

*? ? ? http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

package com.android.systemui.media;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.content.IntentFilter;

import android.util.Slog;

//import com.android.server.policy.PhoneWindowManager;

public class GeiniBroadcastReceiver extends BroadcastReceiver {

? ? private static final boolean DBG = true;

? ? private static final String TAG = "======";

? ? @Override

? ? public void onReceive(Context context, Intent intent) {

? ? ? ? if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {

? ? ? ? ? ? if (DBG) {

? ? ? ? ? ? ? ? Slog.e(TAG, "onReceive BOOT_COMPLETED_ACTION windowmanager:");

? ? ? ? ? ? }? ?

? ? ? ? }? ?

? ? }? ?

}

第二部,在Manifest静态注册广播:

--- a/AndroidManifest.xml

+++ b/AndroidManifest.xml

@@ -270,6 +270,13 @@

?? ? ? ? ? ? android:process=":screenshot"

?? ? ? ? ? ? android:exported="false" />

+? ? ? ? <receiver android:name=".media.GeiniBroadcastReceiver">

+? ? ? ? ? ? <intent-filter>

+? ? ? ? ? ? ? ? <action android:name="android.intent.action.BOOT_COMPLETED"></action>

+? ? ? ? ? ? ? ? <category android:name="android.intent.category.DEFAULT" />

+? ? ? ? ? ? </intent-filter>

+? ? ? ? </receiver>

+

如此便添加完成,可在第一步的onReceive方法中添加自己的目标代码,处理一些逻辑。。。

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-07-13 17:34:48  更:2021-07-13 17:37:12 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/28 23:45:47-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码