lakinduboteju / AndroidNdkBinderExamples

Android NDK (C++) Binder examples : Explains how to implement Android services and clients in C++
108 stars 23 forks source link

Can I send java object by using binder_ndk? #4

Closed houzhj58 closed 3 months ago

houzhj58 commented 3 years ago

I add function in IMyService.aidl void send (Bundle aBundle); and import android.os.Bundle

but when I exec gradlew build, it shows: ERROR: android.os.Bundle: couldn't find import for class android.os.Bundle I guess beceuse there is no cpp files for java Bundle class.

In google website, there is a funciton AParcel_fromJavaParcel, but no function AParcle_toJavaParcel.

So if anyone knows how to send java object by using binder_ndk.

lakinduboteju commented 2 years ago

@houzhj58, Sorry for the long delay in replying.

In IMyService.aidl there is String complexType(in ComplexType aComplexObject); interface method, where ComplexType is an Object type.

If you want to see an example of passing an Java Object from a Java client to a C++ binder service, please take a look at following places in the code.

  1. Java client : JavaBinderClient/src/main/java/.../MainActivity.java (line 85)
  2. C++ service : NdkBinderService/src/main/cpp/MyService.cpp (line 15)

Does this help?