Question

I am developing a windows store app and trying to send files via bluetooth to android (and windows phone) devices.

Based on an example from MSDN I wrote the following code:

public async static void SendAsync(StorageFile file)
{
    var id = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.ObexObjectPush);
    var devices = await DeviceInformation.FindAllAsync(id);
    // -> Returns one windows phone and two android devices

    if (devices.Count > 0)
    {
        // Use the 3th device (android tablet)
        var service = await RfcommDeviceService.FromIdAsync(devices[2].Id);

         // Create a socket and connect to the target
         using (var socket = new StreamSocket())
         {
            await socket.ConnectAsync(
                service.ConnectionHostName,
                service.ConnectionServiceName,
                SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);


            byte[] bytes;
            using (var stream = await file.OpenStreamForReadAsync())
            {
                // stream.Length = 4621038
                bytes = new Byte[stream.Length];

                await stream.ReadAsync(bytes, 0, bytes.Length);
            }

            using (var dataWriter = new DataWriter(socket.OutputStream))
            {
                dataWriter.WriteBytes(bytes);
                Debug.WriteLine("Sending data...");
                var result = await dataWriter.StoreAsync();
                var flushed = await dataWriter.FlushAsync();
                dataWriter.DetachStream();
                Debug.WriteLine("Sending data finished. Result: " + result + " flushed: " +     flushed);
                // Output: 
                // Sending data...
                // Sending data finished. Result: 4621038 flushed: True
            }
        }
    }
}

The Package.appxmanifest looks like:

<m2:DeviceCapability Name="bluetooth.rfcomm">
    <m2:Device Id="any">
        <m2:Function Type="name:obexObjectPush" />
        <m2:Function Type="name:obexFileTransfer" />
        <m2:Function Type="name:genericFileTransfer" />
    </m2:Device>
</m2:DeviceCapability>

When running the code, is seems to work. The app ask "May the [AppName] use your [DeviceName]?" and the bytes seems to be send (dataWriter.StoreAsync() returns the number of bytes to send).

The android device will be activated (light goes on) for a second. But that's all. I would expect to get a request on the android device like: "Windows 8 tries to send a file, accept yes/no", but i don't.

The sent file is not located on the android device (normaly, files send via bluetooth are located in the Bluetooth folder).

Do you have any ideas how to make it work / found the mistake?

Thanks, Jan

No correct solution

OTHER TIPS

Just a brief note just now. OBEX has a protocol, it doesn't just send the file in the raw. I'll write more later but we see something like:

CONNECT->
<-OK
PUT+filename+data->
<-CONTINUE
PUT+FINAL+data->
<-OK
disconnect

You have to implement obex protocol Connect , put ,disconnect operations to do this. please refer This THREAD : Send data through Bluetooth windows 10 universal app

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top