Tag: android bluetooth

在Android中的蓝牙连接期间,不会创建连接(失败或中止)exception

我正在开发一个项目,它使用一个在4.1.2上运行的安卓平板电脑(iball 3G 7271),由MTK处理器和一个RN42蓝牙(PCB上的芯片)组成。这两个模块相互通信以进行传输他们之间的数据通过蓝牙。 我正面临着一些问题。在某些情况下,我反复得到exception,说明“连接未创建(失败或中止)”。我已经找到了如下所述的实例: 我从BlueTerm应用程序(来自playstore)复制了相关代码并制作了一个示例应用程序来测试BT连接.Blueterm是一个测试设备和RN42之间蓝牙连接的应用程序。 1)我将应用程序连接/断开连接到RN42,发现它一直在工作。正在进行正确的连接和断开连接。 2)I模拟电源故障(仅通过关闭RN42模块),然后断开并重新连接app和RN42之间的BT连接,发现平板电脑与RN42重新连接没有太多问题。 3) 重新安装应用程序和BT连接到RN42之间的链接 测试案例1:在重新安装之前,应用程序与RN42断开连接; 结果 – 重新安装后BT重新连接到重新安装的应用程序中的RN42工作正常。 测试案例2:在重新安装之前,应用程序处于连接状态到RN42;结果 – 重新安装后BT重新连接到RN42没有发生。 我追溯到测试案例2的exception是: W/System.err(4603): java.io.IOException: [JSR82] connect: Connection is not created (failed or aborted). W/System.err(4603): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:395) 这是我几天前一次又一次地得到的例外。所以现在我知道什么时候可以抛出这个exception。 注意:对于’测试用例2’,这里甚至卸载并重新安装应用程序然后尝试将应用程序连接到RN42也无法正常工作。我们需要重新启动平板电脑以使应用程序再次连接到BT。此外,我甚至尝试过连接真正的BlueTerm应用程序(在测试用例2中),但它也没有连接。所以我尝试关闭并打开平板电脑的BT.I观察到通过关闭然后打开BT然后尝试建立BT平板电脑和RN42之间的连接正在发生。但是现在,我没有从RN42到平板电脑获得任何输入信号,但是能够将数据从平板电脑发送到RN42。 在三星S2 / grand / nexus设备上进行测试:对于上述测试用例2,在重新安装后,应用程序确实连接到BT,即使在重新安装之前已经/未通过BT连接到RN42。 以下是我的应用程序的代码和日志猫exception: BlueTerm.java @SuppressLint(“HandlerLeak”) public class BlueTerm extends Activity { BluetoothSocket Socket; OutputStream DataOut; InputStream DataIn; // Intent […]

如何通过蓝牙查询远程手机是否支持PBAP?

假设两部Android手机通过蓝牙配对并建立连接。 如何在客户端以编程方式确定远程设备(服务器)是否支持PBAP等蓝牙配置文件? 如果它支持它,那么如何以编程方式启动与远程设备的PBAP会话? 我已广泛搜索网络,到目前为止一直无法找到相同的API支持和文档。 因此,非常感谢任何帮助或指导。 编辑:获取远程设备的UUID会在这里有用吗? 如果是,我怎么知道它是否支持PBAP? 更新:我设法使用以下方法连接到远程设备: mBluetoothSocket = mBluetoothDevice.createRfcommSocketToServiceRecord(applicationUUID); btAdapter.cancelDiscovery(); mBluetoothSocket.connect(); 哪里 private UUID applicationUUID = UUID.fromString(“0000111E-0000-1000-8000-00805F9B34FB”); 适用于免提配置文件模式。 是否有任何这样的固定UUID用于通过PBAP模式连接? UPDATE-2 :现在我可以使用UUID 0000112F与远程设备配对,UUID 0000112F是PSE访问的UUID。 建立连接后,我在远程设备上收到一条消息,询问我是否允许远程设备访问呼叫日志和联系人。 我点击是。

在深度睡眠中连接到蓝牙设备失败

我试图每隔25秒连接一个配对的蓝牙设备,通过AlarmManager调度,触发WakefulBroadcastReceiver启动服务进行连接。 一旦设备进入睡眠状态,一切都会在最初的几个小时内发挥作用,但是大约4-5个小时后,当我认为设备进入深度睡眠状态时,它会开始失效。 我从ParcelFileDescriptor得到一个NullPointerException,声明“FileDescriptor不能为空”。 我已经尝试过搜索这个错误,甚至已经浏览了ParcelFileDescriptor.java中的代码,但我已经走到了尽头。 我在带有Android 4.4.2的Nexus 10上运行它。 尝试连接的代码如下: public GatewaySocket getSocket() throws IOException { if (!BluetoothAdapter.checkBluetoothAddress(macAddress)) return new GatewaySocket(“Address ” + macAddress + ” is not a valid Bluetooth MAC Address”); BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter(); if (bluetooth == null) return new GatewaySocket(“Sorry, no Bluetooth adapter available”); BluetoothDevice device = bluetooth.getRemoteDevice(macAddress); BluetoothSocket btSocket = null; try […]

没有从BLE设备接收数据

我又来了。 所以,长话短说:在我的应用程序中,我试图在Android样本( 那个 )的帮助下从我的BLE设备(tickr心率监视器: 那个 )接收数据。 但是……我没有从我的设备接收数据! 我能够获得特征和描述符,但……仅此而已。 我只是…… 错过了重点 。 这是我的代码: private BluetoothLeService mBluetoothLeService; private ArrayList mGattCharacteristics = new ArrayList(); private BluetoothGattCharacteristic mNotifyCharacteristic; public static final String EXTRAS_DEVICE_NAME = “DEVICE_NAME”; public static final String EXTRAS_DEVICE_ADDRESS = “DEVICE_ADDRESS”; private static final int CONNECTED_ID = 1; private String mDeviceName; private String mDeviceAddress; private boolean mConnected = […]

Ble扫描设备的服务而不连接它

我想用BLE扫描一些设备。 我只想展示我的设备,所以我知道我得到了设备的名称,如果它是好的,我把它放在我的列表中。 if (device.getName().contains(DEVICE_NAME)) { mDevices.put(device.hashCode(), device); invalidateOptionsMenu(); } 我的问题是,如果我更改设备的名称,则此检查将为false。 所以我看看是否有可能得到一些我添加的服务的uuid用不会改变的东西做检查。 唯一的方法是连接到设备上做device.connectGatt(this, false, mGattCallback); 和gatt之后我发现了服务但是,有没有可能从没有连接的设备发现一些服务?

片段:蓝牙服务和片段连接

我对我的项目进行了调试,我的3.片段无法连接蓝牙服务。 这包括向其他设备发送消息。 我的连接是启动第一个片段我的设备ID和设备名称应该保持蓝牙服务但我连接下面的代码我的连接null和ConnectedThread返回null对象。 那我怎样才能再次在我的片段中连接蓝牙服务java? 我在片段上称这一行 mBluetoothConnection = new BluetoothConnectionService(getActivity().getApplicationContext()); 并在BluetoothService.java中编写函数: button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { byte[] bytes = editText.getText().toString().getBytes(Charset.defaultCharset()); mBluetoothConnection.write(bytes); } }) 我在mBluetoothConnection.write(bytes);上的断点mBluetoothConnection.write(bytes); 这一行和每个ConnectedThread,outputstream都返回null,为什么? 这是我的服务: public class BluetoothConnectionService { private static final String TAG = “BluetoothConnectionServ”; private static final String appName = “MYAPP”; private static final UUID MY_UUID_INSECURE = UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB”); private […]

蓝牙发送和接收文本数据

我是Android开发的新手,我想创建一个使用蓝牙发送和接收文本的应用程序。 我得到了关于发送文本在逻辑上工作的一切,但当我尝试在手机中测试它时,我看不到界面。 这是Main Activity代码 import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.os.Build; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.widget.TextView; import android.widget.EditText; import android.widget.Button; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Set; import […]