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>
相关推荐
__Witheart__13 小时前
搭建编译 HW-T3568 安卓固件的环境
android
Bowen_J13 小时前
Flutter 屏幕旋转适配
android·flutter·ios
程序员陆业聪21 小时前
绕过Frida/Xposed的最后防线:SVC直接系统调用与Native反Hook实战
android
程序员陆业聪21 小时前
WebView与原生JS交互:JSBridge生产级实现与安全防护
android
我命由我123451 天前
Android 开发问题:MlKitException: An internal error occurred during initialization.
android·java·java-ee·android jetpack·android-studio·androidx·android runtime
Meteors.1 天前
Android自定义 View 三核心方法详解
android
2501_916007471 天前
前端开发常用软件与工具全面指南
android·ios·小程序·https·uni-app·iphone·webview
赏金术士1 天前
Android Tinker 热修复集成与使用指南 1.9.15.2
android·热修复·tinker
2603_954138391 天前
安卓误删文件先别慌!5个实用小技巧指南教你补救
android·智能手机
波诺波1 天前
5-SOFA可变形的3D物体 5-elasticity.scn
android