相关疑难解决方法(0)

Android蓝牙文件发送

我想在Android设备上通过蓝牙发送文件.我做了发现,连接并制作了一个蓝牙插座.问题是当我在蓝牙套接字的输出流中写字节数组时,接收方虽然接受正在发送的内容但没有收到任何内容.

这就是我在做什么(坏的是蓝牙适配器)

请指教.

try
    {
        BluetoothDevice dev = bad.getRemoteDevice(a);
        bad.cancelDiscovery();

        dev.createRfcommSocketToServiceRecord(new UUID(1111, 2222));
        Method m = dev.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
        bs = (BluetoothSocket) m.invoke(dev, Integer.valueOf(1));
        bs.connect();
        tmpOut = bs.getOutputStream();
    }catch(Exception e)
    {

    }

    File f = new File(filename);

    byte b[] = new byte[(int) f.length()];
    try
    {
        FileInputStream fileInputStream = new FileInputStream(f);
        fileInputStream.read(b);
    }catch(IOException e)
    {
        Log.d(TAG, "Error converting file");
        Log.d(TAG, e.getMessage());
    }

    try {
        tmpOut.write(b);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

android bluetooth file transfer

21
推荐指数
1
解决办法
6707
查看次数

标签 统计

android ×1

bluetooth ×1

file ×1

transfer ×1