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>
相关推荐
_阿南_4 小时前
Android文件读写和分享总结
android
通玄13 小时前
Jetpack Compose 入门系列(六):Navigation 3 页面导航
android
rocpp15 小时前
Android 多语言切换实战:从 Context 到 Android 13 应用语言适配
android·kotlin
释然小师弟16 小时前
Android开发十年:反思与回顾
android·后端·嵌入式
黄林晴18 小时前
用了这么久 Koin Scope,原来一直都用错了?
android·kotlin
爱勇宝1 天前
我做了一个只用来搜歌词的小 App
android·前端·后端
众少成多积小致巨1 天前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
Coffeeee2 天前
如何使用Glide和Coil加载WebP动图
android·kotlin·glide
Kapaseker2 天前
5 分钟搞懂 Kotlin DSL
android·kotlin
恋猫de小郭2 天前
AI Agent 开发究竟是啥?如何用 AI 开发 Agent ?深入浅出给你一套概念
android·前端·ai编程