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>
相关推荐
alexhilton38 分钟前
探究Android Views、Flutter和Compose如何渲染你的UI
android·kotlin·android jetpack
Lesile3 小时前
Android:Hilt框架入门 · 在ViewUI和ComposeUI下的应用
android·android jetpack
用户423816229074 小时前
Android 16 WebView 页面顶部挖孔/通知栏不能显示UI问题排查
android
weixin_727535624 小时前
Loop 已死,Graph 新生:AI 工作流的范式革命
android·人工智能·rxjava
严同学正在努力5 小时前
从备份到恢复:我用 30 分钟恢复了误删的核心业务表
android·java·数据库·ai
梦想三三6 小时前
LangChain Output Parser 实战:从字符串到结构化数据的完整指南
android·服务器·langchain·github·uv
爱笑鱼8 小时前
Binder(八):远端进程死了,BinderProxy 为什么还能收到通知?
android
Android-Flutter8 小时前
Kotlin 冷流与热流详解
android·kotlin
zhangphil8 小时前
Android ContentProvider/ContentResolver读图片,跨进程 IPC慢
android
yueqc19 小时前
Android .so 文件压缩
android·so·包体积