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>
相关推荐
wy3136228219 小时前
android——开发中的常见Bug汇总与解决方案(闪退)
android·bug
小小测试开发10 小时前
实战派SQL性能优化:从语法层面攻克项目中的性能瓶颈
android·sql·性能优化
QuantumLeap丶11 小时前
《Flutter全栈开发实战指南:从零到高级》- 26 -持续集成与部署
android·flutter·ios
StarShip12 小时前
从Activity.setContentView()开始
android
千里马学框架12 小时前
重学SurfaceFlinger之Layer显示区域bounds计算剖析
android·智能手机·sf·安卓framework开发·layer·surfaceflinger·车载开发
nono牛13 小时前
安卓休眠与唤醒流程
android
二流小码农14 小时前
鸿蒙开发:个人开发者如何使用华为账号登录
android·ios·harmonyos
StarShip14 小时前
Android View框架概览
android·计算机图形学
愤怒的代码14 小时前
解析Android内存分析的指标
android·app
summerkissyou198715 小时前
android-hardware/interfaces/automotive和hardware/libhardware/include/hardware区别
android