Tom*_*ken 5 android bluetooth android-ndk core-bluetooth
我正在寻找一种从我的Android智能手机(HTC Desire with Android 4.0.1)定期进行蓝牙查询的方法.设备已植根,并且是安装的自定义Rom,因此我具有完全权限.我已经编写了一个shellcript,它使用hcitool,hciconfig和hcidump来进行查询.到目前为止工作正常,但对我来说这有点慢.我想这是因为我使用android-app从linux执行一个shellcript的肮脏的解决方法.虽然通过我的应用程序杀死执行的进程我遇到了问题.
所以我想找到一种从Android API查询BT设备的方法.我发现现在没有可能做到这一点,但我读到了可能符合我要求的bluez API.有没有人对我有任何链接,提示或建议?
我没有找到任何有用的东西:/
提前致谢.
编辑(2012-09-28):
好的,我想我现在离解决方案更近一些了.我从bluez.org下载了blueZ库的源代码 然后我将重要文件(hci.h,bluetooth.h,hcilib.h及其源文件)放入我的android项目的jni文件夹中,并将它们编译到我的共享库中.我在函数周围编写了一个JNI Wrapper
hci_inquiry(int dev_id, int len, int nrsp, const uint8_t *lap,inquiry_info **ii, long flags)
Run Code Online (Sandbox Code Playgroud)
并遵循建议的这本书做我的询问.一切都很好,直到这里.
但是当我开始查询时,功能
dev_id = hci_get_route(NULL);
Run Code Online (Sandbox Code Playgroud)
总是返回-1,我无法继续.
蓝牙已激活,我已尝试授予对我的应用程序的root访问权限.不是更好:(
我到底做错了什么?是不是允许从Android应用程序使用BlueZ HCI命令?我的意思是JBlueZ什么都不做呢?
我的本机代码如下所示:
inquiry_info *ii = NULL;
int max_rsp, num_rsp;
int dev_id, sock, len, flags;
int i;
char addr[19] = { 0 };
char name[248] = { 0 };
dev_id = hci_get_route(NULL);
if (dev_id < 0 ) {
LOGI("ERROR ON finding Device ID");
return;
}
sock = hci_open_dev( dev_id );
if (sock < 0) {
LOGI("ERROR ON opening socket");
return;
}
len = 8;
max_rsp = 255;
flags = IREQ_CACHE_FLUSH;
ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
//##################################################################################
LOGI("INQUIRY Executed!!!");
(*env)->CallVoidMethod(env, obj, callBackID, num_rsp);
free(ii);
close(sock);
Run Code Online (Sandbox Code Playgroud)
感谢您的任何帮助.