Android AIDL 服务未执行

问题描述

我使用的是 Android Automotive 11 环境,以下代码实际上也无法在常规 Android 11 环境下运行。

我使用我从源 Android 11 r35 构建的模拟器。

当我尝试打开 AIDL 服务时出现以下错误

权限监视器:NameNotFoundException

broadcastQueue:不允许后台执行

enter image description here

代码如下:

public class MySimpService extends Service {

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return new SimpServiceImp();
    }
}

SimpServiceImp 类:

public class SimpServiceImp extends ISimp.Stub {

    @Override
    public int add(int a,int b) throws remoteexception {
        return a+b;
    }

    @Override
    public int sub(int a,int b) throws remoteexception {
        return a-b;
    }
}

AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AIDLService" >

    <service android:name=".MySimpService">
        <intent-filter>
            <action android:name="com.example.aidlservice.MySimpService"/>
        </intent-filter>
    </service>
</application>

解决方法

有很多基本的 Android 问题导致它无法正常工作。 部分原因是服务必须有通知才能保持活动状态。

https://github.com/NewstHet/AndroidAidlClient https://github.com/NewstHet/AndroidAIDLService

Github 链接包含使用 Android 11 API 30 的有效 AIDL 服务。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...