android - 为何设备启动完成时,我在 AndroidManifest.xml 中声明未注册到系统
问题描述
当系统启动时,我编写了一个 apk 来启动我的服务,这个 apk 没有任何活动。我只是在它的 AndroidManifest.xml 中声明了一个,但是当系统启动完成时接收器没有注册到系统。
安卓平台为安卓9.0。我需要将我的系统从 O 升级到 P。
1.我在android 8.1上测试过,这个应用可以注册receiver并在系统启动完成时接收到广播启动Service。
2.我检查了我的android设备中的/data/system/packages.xml,我的应用程序已经存在。
3.我使用此命令检查注册到系统的接收器,但我在 manifest.xml 中声明的接收器不存在。
adb shell sumpsys activitys b 'com.xxx.xxx.xxservice'
4.我也使用这个命令来检查存在的应用程序。
adb shell pm list packages | grep 'com.xxx.xxx.xxservice'
5.我在SELinux ON/OFF上测试过,结果是一样的。没有注册接收方。
6.系统中还有一个这样的应用程序,它可以注册它的接收器并接收相同的广播(com.xxx.xxx.FAST_BOOT)。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.xxx.xxservice"
android:sharedUserId="android.uid.system">
<permission android:name="xxx.xxx.xxx.XXX_SERVICE_PERMISSION"
android:label="@string/xxxService"
android:description="@string/xxxService"
android:protectionLevel="signatureOrSystem" />
<uses-permission android:name="com.xxx.xxx.RECEIVE_FAST_BOOT" />
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:process="system">
<uses-library android:name="ServiceUtils" />
<receiver android:name="com.xxx.xxx.xxx.AppReceiver">
<intent-filter>
<action android:name="com.xxx.xxx.FAST_BOOT"/>
</intent-filter>
</receiver>
<service android:name="com.xxx.xxx.xxx.Service" />
</application>
</manifest>
解决方案
you forgot to use permission in your manifest :
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
推荐阅读
- r - lapply中的RSelenium StaleElementReference错误
- swiftui - SwiftUI:点击更改 TectField 背景颜色
- python - 模拟数据库游标并断言传递给游标函数的值
- r - 在 R 中的文本文件中提取重复出现的行/模式
- python - 如何在python中制作一个矩阵数组?
- java - 当小时、分钟和秒为零时,OffsetDateTime 解析忽略秒
- python - 请参阅下面的代码中的 def __str__(self):。它不影响输出,但应该。期待帮助
- python - 需要帮助理解这个 Python 列表语法
- reactjs - React 中的语义 UI 卡片组
- python - 删除数据集中的所有行 >= 一个值