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>
相关推荐
阿pin13 小时前
Android随笔-kotlin withContext
android·kotlin·withcontext
树码小子13 小时前
开启 IDEA 中的断言功能
android·java·intellij-idea
Kslient13 小时前
HeaderBehavior
android
Android-Flutter14 小时前
android 动画详解
android·kotlin
小孔龙20 小时前
GraphicBuffer 跨进程共享
android
行业研究员20 小时前
Android内置GPS与腾讯地图定位技术对比分析
android·android定位·腾讯地图定位
Android-Flutter21 小时前
android WMS 详解(二)
android·kotlin
游戏开发爱好者821 小时前
App Store 上传 IPA 自动化,.p8 密钥认证与 CI/CD 接入实战
android·运维·ci/cd·小程序·uni-app·自动化·iphone
游戏开发爱好者81 天前
iOS 推送怎么配置,APNs 推送证书、设备库与群发
android·ios·小程序·https·uni-app·iphone·webview
阿pin1 天前
Android随笔-kotlin 高阶函数
android·kotlin·高阶函数