我想从我自己的应用程序调用android源代码中的com_android_bluetooth_hid.cpp
中提供的函数。目标Android版本是> = 4.4和< = 5.x.我理解JNI,可以编译我自己的代码并从我自己的应用程序调用。
可以从我的应用程序调用android的库吗?如何
另外,要调用该特定cpp文件中的函数,是否需要BLUETOOTH和BLUETOOTH_ADMIN权限或其他内容(其他权限或根目录)?
答案 0 :(得分:0)
The cleanest way to call Android's CPP code is, generally, copying the relevant pieces to your repository and building as part of your app. Following this approach, your app will only call the public APIs - either Java or C/C++.
But this may not be relevant in cases when this code must run with special permissions, as system service, like mediaserver or Bluetooth stack.
I am afraid that the code you wish to run belongs to this second category, therefore none of the available tricks will not help.
On the other hand, a custom ROM may be a solution you are looking for. It may happen that you don't need to forge a full system. It may be enough to use a rooted device and replace the bluetooth service with your custom one.
I would still advise you to provide the missing callbacks for the service, instead of calling the functions directly from your app: you better not mix contexts between a user-space app and system service.