android bindService打开失败

在写demo验证SurfaceControlViewHost的时候,bindService提示

Unable to start service Intent U=0: not found

在源代码里搜了下,找到是在如下方法里面里面打印出来的

java 复制代码
// frameworks/base/services/core/java/com/android/server/am/ActiveServices.java
retrieveServiceLocked {
    ....
    if(mAm.getPackageManagerInternal().filterAppAccess(r.packageName,callingUid,
        userId)){
        Slog.w(TAG_SERVICE,"Unable to start service "+service+" U="+userId
        +": not found");
        returnnull;
    }
    ....
}

后面查了下,发现是包可见性的变更引起的异常

Android 11 中的软件包可见性 | Android Developers
Android 上的软件包可见性过滤 | Android Developers

解决方案,在使用的bindService的应用的AndroidManifest.xml里面加上queries,类似如下

java 复制代码
    <queries>
        <package android:name="com.example.host"/>
    </queries>
相关推荐
Pika6 小时前
深入浅出 Compose 测量机制
android·android jetpack·composer
木易 士心11 小时前
MPAndroidChart 用法解析和性能优化 - Kotlin & Java 双版本
android·java·kotlin
消失的旧时光-194311 小时前
Kotlin Flow 与“天然背压”(完整示例)
android·开发语言·kotlin
ClassOps11 小时前
Kotlin invoke 函数调用重载
android·开发语言·kotlin
努力学习的小廉11 小时前
初识MYSQL —— 数据类型
android·数据库·mysql
Lei活在当下15 小时前
【业务场景架构实战】7. 多代智能手表适配:Android APP 表盘编辑页的功能驱动设计
android·设计模式·架构
手机不死我是天子19 小时前
《Android 核心组件深度系列 · 第 2 篇 Service》
android
前行的小黑炭19 小时前
Compose页面切换的几种方式:Navigation、NavigationBar+HorizontalPager,会导致LaunchedEffect执行?
android·kotlin·app
前行的小黑炭20 小时前
Android :Comnpose各种副作用的使用
android·kotlin·app
BD_Marathon1 天前
【MySQL】函数
android·数据库·mysql