Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: transfer byte array with AIDL

Tags:

android

aidl

I need to transfer byte array between an Android service and client. I have tried to define an aidl interface like:

interface IMyService {
    int putBytes(String key, in List<Byte> bytes);
    int getBytes(String key, out List<Byte> bytes);    
}

But, it doesn't compile. The error is:

[aidl] E:\workspace\RAMService\src\com\connexis\service\mem\IRAMService.aid
l:14 parameter bytes (2) unknown type List<Byte>

Could someone help me? Thanks in advance!

like image 914
Dagang Avatar asked Nov 30 '12 07:11

Dagang


People also ask

How does AIDL work on Android?

aidl file, the Android SDK tools generate an IBinder interface based on the . aidl file and save it in the project's gen/ directory. The service must implement the IBinder interface as appropriate. The client applications can then bind to the service and call methods from the IBinder to perform IPC.

What data types are supported by AIDL?

all native Java data types like int,long, char and Boolean.

Where do I put AIDL files?

I use Android Studio 4.1, just right click mouse -> New -> AIDL -> AIDL File. A file will be created and placed in the [src/main/aidl] folder automatically. The aidl folder will also be created if it does not exist.

What is AIDL file android?

An AIDL file is used by Android app developers to enable communication between different apps. It contains Java source code that defines an interface, or contract, for how apps can communicate with each other. AIDL is an implementation of the Interprocess Communication (IPC) protocol provided by Android.


1 Answers

Try using byte[] instead of List, it works for me.

interface IMyService {
    int putBytes(String key, in byte[] bytes);
    int getBytes(String key, out byte[] bytes);    
}

AIDL only support primitives, String, CharSequence, List, Map. You can have List but never List

AIDL doc

like image 59
zhao chang Avatar answered Sep 20 '22 05:09

zhao chang