首页 > 解决方案 > 为何设备启动完成时,我在 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>

标签: androidandroid-broadcast

解决方案


you forgot to use permission in your manifest :

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

推荐阅读