我的目标是创建一种project。我想通过蓝牙将一些字符串发送到PC上的Proteus。在MIT App Inventor(MIT app)中进行的应用程序可以工作。我想在Android Studio中创建类似的应用。我使用这个Android Studio app by mitchtabian,可以编写一些文本并将其发送到绑定设备。 问题:我无法创建RfcommSocket。我也尝试创建UnsecureRfcommSocket,但是它没有用。
public void run(){
BluetoothSocket tmp = null;
Log.i(TAG, "RUN mConnectThread ");
// Get a BluetoothSocket for a connection with the
// given BluetoothDevice
try {
Log.d(TAG, "ConnectThread: Trying to create InsecureRfcommSocket using UUID: "
+MY_UUID_INSECURE );
tmp = mmDevice.createRfcommSocketToServiceRecord(deviceUUID);
} catch (IOException e) {
Log.e(TAG, "ConnectThread: Could not create InsecureRfcommSocket " + e.getMessage());
}
mmSocket = tmp;
Log.d(TAG, "run: mmSocket = tmp");
// Always cancel discovery because it will slow down a connection
mBluetoothAdapter.cancelDiscovery();
// Make a connection to the BluetoothSocket ....
还有日志:
I / BluetoothConnectionServ:运行mConnectThread
D / BluetoothConnectionServ:ConnectThread:尝试使用UUID创建InsecureRfcommSocket:8ce255c0-200a-11e0-ac64-0800200c9a66
D / BluetoothConnectionServ:运行:mmSocket = tmp
W / BluetoothAdapter:调用getBluetoothService()且没有BluetoothManagerCallback
W / DecorView [Connecting Bluetooth]:导航栏的可见性很低,color = ffffffff,hasLightNavBar = true,isFloating = true
D / BluetoothSocket:close()此:android.bluetooth.BluetoothSocket@eeeeaba,频道:-1,mSocketIS:android.net.LocalSocketImpl$SocketInputStream@d1acd6b,mSocketOS:android.net.LocalSocketImpl$SocketOutputStream@ac240c8mSocket:android.net。 LocalSocket @ 722b561 impl:android.net.LocalSocketImpl@710f886 fd:java.io.FileDescriptor@b96d547,mSocketState:INIT
D / BluetoothConnectionServ:运行:封闭套接字。
D / BluetoothConnectionServ:运行:ConnectThread:无法连接到UUID:8ce255c0-200a-11e0-ac64-0800200c9a66
D / BluetoothConnectionServ:已连接:正在启动。
D / BluetoothConnectionServ:ConnectedThread:正在启动。
E / BluetoothConnectionServ:写入:读取输入流时出错。插座已关闭