Tag: bluetooth

使用蓝牙将PC连接到Android手机

我想在我的电脑和Android手机之间建立一个蓝牙连接,并希望从我的电脑发送一个字符串到Android手机。 我正在使用Bluecove 2.1.0。 我能够发现附近的蓝牙设备现在我想配对设备并从PC发送字符串到android手机提前谢谢这是我用于搜索设备的代码 import java.io.OutputStream; import java.util.ArrayList; import javax.bluetooth.DataElement; import javax.bluetooth.DeviceClass; import javax.bluetooth.DiscoveryAgent; import javax.bluetooth.DiscoveryListener; import javax.bluetooth.LocalDevice; import javax.bluetooth.RemoteDevice; import javax.bluetooth.ServiceRecord; import javax.bluetooth.UUID; import javax.microedition.io.Connector; import javax.obex.ClientSession; import javax.obex.HeaderSet; import javax.obex.Operation; import javax.obex.ResponseCodes; public class MyDiscoveryListener implements DiscoveryListener{ private static Object lock=new Object(); public ArrayList devices; public MyDiscoveryListener() { devices = new ArrayList(); } […]

蓝牙设备发现出错

我尝试使用以下代码来发现蓝牙设备 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Vector; import javax.bluetooth.DeviceClass; import javax.bluetooth.DiscoveryAgent; import javax.bluetooth.DiscoveryListener; import javax.bluetooth.LocalDevice; import javax.bluetooth.RemoteDevice; import javax.bluetooth.ServiceRecord; import javax.bluetooth.UUID; /** * * Class that discovers all bluetooth devices in the neighbourhood, * * Connects to the chosen device and checks for the presence of OBEX push service in it. * and […]

java中的蓝牙(J2SE)

我是蓝牙的新手,这是我想做的事情,我想获得连接到我的电脑上的蓝牙的设备信息,并将信息写入文件。 我应该使用哪种api以及如何实现。 我遇到了蓝鸟,但在一些搜索中,我发现蓝色的巧克力在64位电脑上不起作用。 我现在应该怎么做。我希望这适用于32位和64位PC。 Thankx

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 […]

如何使用BlueCove在带Mac的MacBook上使用蓝牙?

我想在我的MacBook Air笔记本电脑上实现一个使用蓝牙的Java应用程序。 我尝试使用Java蓝牙库BlueCove 。 我试图实现第一个示例DeviceDiscovery但它抛出一个带有消息的BluetoothStateException : BlueCove library bluecove not available 。 我已将bluecove-2.1.0.jar添加到Eclipse中的Build Path中。 问题是什么? 如何在MacBook Air中使用BlueCove?

如何使用Java Android SDK进行良好的实时数据流传输

我有一个自制的蓝牙设备,测量500Hz的心电图:设备每2 ms发送9个字节的数据(标头,ECG测量,页脚)。 所以这大约是9 * 500 = 4.5kbytes / s的数据流。 我有一个C ++ Windows程序能够连接设备并检索数据流(用Qt / qwt显示)。 在这种情况下,我使用Windows控制面板来绑定设备,并使用boost serial_port接口通过虚拟COM端口连接它。 这完美地工作,我实时接收我的数据流:我每2ms左右得到一个测量点。 我通过QtCreator 3.0.1(Qt 5.2.1)在Android上移植了整个程序。 似乎无法通过boost访问虚拟COM端口(可能SDK权限不允许),因此我编写了一段Java代码来打开和管理蓝牙连接。 所以我的应用程序仍然是C ++ / Qt,但只有连接和读取设备数据的层在Java中重新编写(用createInsecureRfcommSocketToServiceRecord打开连接): 用于读取数据的Java代码: public int readData( byte[] buffer ) { if( mInputStream == null ) { traceErrorString(“No connection, can’t receive data”); } else { try { final boolean verbose = false; int […]

android 4.3蓝牙ble不叫onCharacteristicRead()

我已经将通知设置为android,它没有调用方法onCharacteristicRead() ???? 它不会进入该function。 为什么会这样? 任何帮助表示赞赏 请求解决方案。 这是我的代码: private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { if (newState == BluetoothProfile.STATE_CONNECTED) { Log.i(TAG, “Connected to GATT server.”); // Attempts to discover services after successful connection. Log.i(TAG, “Attempting to start service discovery:” + mBluetoothGatt.discoverServices()); } else if (newState […]