首页 > 解决方案 > TelephoneManager.getAllCellInfo() 在服务内返回 null

问题描述

如果我试图在没有启动应用程序的情况下在服务中获取 TelephoneManager.getAllCellInfo()(手机启动完成后 - 通过事件启动服务) TelephoneManager.getAllCellInfo() 返回 null。

这是前台服务,它有这个清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.signalsense.signalsense_library">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application>
        <service android:name="com.signalsense.signalsense_library.NetworkCollectionService"
            android:foregroundServiceType="location"
            android:enabled="true"
            android:exported="true"/>
    </application>

</manifest>

但是,如果我将使用应用程序启动此服务(例如,通过单击应用程序 - 它也会自动启动服务)一切正常。

服务启动代码是平等的。我不明白。也许在没有应用程序的情况下访问 getAllCellInfo() 有一些限制?也许是因为权限“ACCESS_FINE_LOCATION”是危险的,它是为应用程序提供的,并且只适用于应用程序?请帮忙!

标签: androidservicetelephonymanager

解决方案


推荐阅读