Bluetooth not sending file to other device

前端 未结 4 1349
深忆病人
深忆病人 2021-02-14 12:41

It is already asked but i didn\'t find any solution. For bluetooth application i am using the bluetoothShare.class .

My source code for sending the file to

4条回答
  •  醉梦人生
    2021-02-14 13:10

    Maybe you can try another solution with BufferedWriter and BufferedReader.

    Here is a snipped code:

                BluetoothDevice mmDevice;
                Set mBluetoothAdapter;
    
                BluetoothAdapter bAdapter = BluetoothAdapter
                        .getDefaultAdapter();
                mBluetoothAdapter = bAdapter.getBondedDevices();
    
                for (BluetoothDevice bc : mBluetoothAdapter) {
                    if (bc.getName().indexOf("name_of_bluetoothdevide") != -1) {
                        UUID uuid = UUID
                                .fromString("00001101-0000-1000-8000-00805F9B34FB"); // Standard
                                                                                        // SerialPortService
                                                                                        // ID
                        mmDevice = bc;
                        BluetoothSocket mmSocket = mmDevice
                                .createInsecureRfcommSocketToServiceRecord(uuid);
                        bAdapter.cancelDiscovery();
                        mmSocket.connect();
                        BufferedWriter Writer = new BufferedWriter(
                                new OutputStreamWriter(
                                        mmSocket.getOutputStream()));
                        Writer.write("Bluetooth connected!");
                        Writer.flush();
    
                        app.setmSocket(mmSocket);
    
                        break;
                    }
                }
    

    And for reading:

      BufferedReader Reader = new BufferedReader(
                        new InputStreamReader(mmSocket.getInputStream()));
                receivedMsg = Reader.readLine();
    

    Hope it can help you.

提交回复
热议问题