最近,我尝试让配对过程以编程方式工作,并且成功了。但我最近发现我的应用程序的用户可以连接到几个“有趣的”设备。所以我必须提示用户选择要连接的设备
所以我必须将用户连接到已经配对的蓝牙设备。但我的努力都没有效果。我尝试使用以下命令再次运行配对过程:
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
还有以下内容:
Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
mmSocket = (BluetoothSocket) m.invoke(mmDevice, 1);
Run Code Online (Sandbox Code Playgroud)
这是我已经实现的方法,也是将我的手机与嵌入式蓝牙设备配对的唯一有效方法
所以我的问题是:
软件(如Mozilla Firefox、Thunderbird)可以加载opensc模块(linux上为opensc-pkcs11.so,windows上为opensc-pkcs11.dll)并使用OpenSC支持的所有智能卡进行身份验证、签名和解密。我的问题是我们如何在 android 中做同样的事情(在哪里存储 opensc 模块,如何访问外部令牌等)。例如,应用程序如何使用 opensc 模块通过 nfc 和/或蓝牙接口访问智能卡令牌。
我不喜欢像寻找 android 那样闪烁我的 android。我请求任何建议或示例。提前致谢。
Android中BluetoothLeScanner的setReportDelay的目的是什么?我无法想象为什么有人会延迟收到报告......
android bluetooth-lowenergy android-bluetooth altbeacon android-5.0-lollipop
连接蓝牙设备的正常方式是通过配对。
\n\n我们需要以非正常方式连接到设备:仅使用蓝牙 MAC 地址。我们不希望系统提示输入 PIN。
\n\n我们知道该设备支持此技术,但我们找不到在 Android 上执行此操作的方法。
\n\n缩写代码如下所示:
\n\n String mac_address = \xe2\x80\x9c00:11:22:33:44:55\xe2\x80\x9d\n BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();\n\n BluetoothDevice bluetoothDevice = mBluetoothAdapter.getRemoteDevice(mac_address);\n\n Method m = bluetoothDevice.getClass().getMethod("createRfcommSocket", \n new Class[] {int.class});\n BluetoothSocket socket = (BluetoothSocket) m.invoke(device, 1);\n\n socket.connect();\n
Run Code Online (Sandbox Code Playgroud)\n\n问题是,系统socket.connect()
会提示我们输入 PIN 码。此设备不需要 PIN,因此我们不希望系统提示输入 PIN。
我们不需要知道 PIN 码的原因是:
\n\n我们如何修改代码,使其不会提示输入 PIN 码?
\n\n[编辑测试评论中的建议]
\n\n我们测试了 createInsecureRfcommSocketToServiceRecord 方法,如下所示:
\n\nParcelUuid list[] = device.getUuids();\nBluetoothSocket socket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(list[0].getUuid());\n …
Run Code Online (Sandbox Code Playgroud) 所以我有一个蓝牙设备,我听设备上的按钮按下,并尝试在按下按钮时拍照。问题是我没有找到任何解决方案来做到这一点。
} else if (destination.equals(APPLICATION_ACTION_DESTINATION_OPEN_CAMERA)) {
Intent intent1 = new Intent("android.intent.action.CAMERA_BUTTON");
intent1.putExtra("android.intent.extra.KEY_EVENT", new KeyEvent(0, KeyEent.KEYCODE_CAMERA));
context.sendOrderedBroadcast(intent1, null);
intent1 = new Intent("android.intent.action.CAMERA_BUTTON");
intent1.putExtra("android.intent.extra.KEY_EVENT", new KeyEvent(1, KeyEvent.KEYCODE_CAMERA));
context.sendOrderedBroadcast(intent1, null);
} else if (destination.equals(APPLICATION_ACTION_DESTINATION_TAKE_PHOTO)) {
}
Run Code Online (Sandbox Code Playgroud)
我发现做到这一点的唯一方法是使用:
Instrumentation.sendKeyDownUpSync();
Run Code Online (Sandbox Code Playgroud)
问题是我需要注册 INJECT_EVENTS 权限,该权限仅授予系统应用程序。
有人设法做到这一点吗?
android android-intent android-camera android-event android-bluetooth
我正在尝试读取连接的蓝牙 LE 设备(Genuino 101)的浮动特性。出于测试目的,设备提供带有硬编码值“55.3”的 FloatCharacteristic。虽然我能够收到一个以某种方式类似于浮点数的字符串,但我无法读取实际的浮点值。
这是处理字符串的代码片段:
// For all other profiles, writes the data formatted in HEX.
final byte[] data = characteristic.getValue();
if (data != null && data.length > 0) {
final StringBuilder stringBuilder = new StringBuilder(data.length);
for(byte byteChar : data)
stringBuilder.append(String.format("%02X ", byteChar));
intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString());
}
Run Code Online (Sandbox Code Playgroud)
这是直接从android 开发者主页的https://developer.android.com/samples/BluetoothLeGatt/index.html BLE 演示项目复制的。然后此代码段处理意图:
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("Broadcast received");
final String action = intent.getAction(); …
Run Code Online (Sandbox Code Playgroud) 我打电话:
bleScanner.startScan(leScanCallback);
Run Code Online (Sandbox Code Playgroud)
我确实得到了 onScanResults。
但是我从来没有得到过 onBatchScanResults,所以我想知道什么时候会调用它。我这样问是因为我担心该函数可能会在不同的条件下被调用(即当找到很多蓝牙设备时)。
在这个问题中,@nhoxbypass 提供了此方法,用于将找到的蓝牙设备添加到列表中:
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Message msg = Message.obtain();
String action = intent.getAction();
if(BluetoothDevice.ACTION_FOUND.equals(action)){
//Found, add to a device list
}
}
};
Run Code Online (Sandbox Code Playgroud)
但是,我不明白如何获得对找到的设备的引用,这该怎么做?
我无权对原始问题发表评论,所以我选择在这里扩展它。
我正在通过蓝牙向第二台设备发送一个简单的文本文件。根据我是接受还是拒绝接收设备中的文件,发送设备中会显示操作系统级别的 Toast 消息,即“文件已发送”或“文件未发送”。如何在发送设备中访问这些事件?
我的应用程序中有一个开发人员选项窗格,开发人员可以在其中输入设备的测试 MAC 地址。问题是如何正确验证它?Android 是否有一些开箱即用的方法来执行此操作?