简体   繁体   中英

Android NDK,JNI,Bluetooth : Designing the Android Application which is having C++ source code/library with Bluetooth APIs/methods ,using JNI

I need to design the Android Application which is having C++ source code/library with Bluetooth APIs/methods ,using JNI,NDK. I don't have much knowledge of Bluetooth APIs.

Pre-conditions

  1. Existing Windows,Linux,Mac OS software code written in C++. This is the software(Desktop) which connects and controls the Bluetooth device(Speaker etc)

  2. The existing whole code is in C++.

  3. Need to use this existing C++ source code or can use it as library in Android Application.

Queries :

  1. I should use MVC or MVP architecture?
  2. How to link C++ Bluetooth APIs with Android Bluetooth APIs?
  3. How to have two way communication between Android and C++ code and vice versa.(How to use callbacks and Registering for events for C++? Note : Currently I am not exposed to actual existing Windows , MacOS , Linux software code , so don't know the current communication structure. If anyone knows I please explain)
  4. Does Android Bluetooth APIs suffice or for extended support developers use native code(C++)?
  1. I personally would go for MVC. In my opinion it would suite the functionality better.
  2. There is absolutely no need to link native and android BT APIs. Since both serve the same purpose its upto you which 1 to use. The android BT stack is a bit unstable, but already has all the implementation needed. Unless the native code is going to provide some kind of value addition or different functionality, there is no point in re-inventing the wheel.
  3. You can use the SO files of the respective C++ lib and access them using JNI. To and fro communication is not a problem. For implementing callbacks you will find code snippets. For instance, How to create callbacks between android code and native code?
  4. As mentioned before, if your native lib does not do anything more than what the android APIs do then avoid it as far as possible.

Answers

  1. Architectures are flexible enough to fit to any requirement and it is entirely your call which one to use.
  2. Basically, if you have something in C++, you will have to write a JNI wrapper. You could bundle it together in a single jar and import it in your project and can use it using the exposed APIs
  3. Learn JNI and its usage.
  4. Android introduced Bluetooth Low Energy to communicate remote devices using bluetooth tech. If they would suffice your requirement or not entirely depends on your requirement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM