'Android Discoverable Listen For Incoming File

I request the user to turn on bluetooth and become discoverable for 120 seconds. During the 120 seconds I will be receiving a file transfer allert from a different device. I want to grab the text from that file. Is the best way to accept the file and let it download to the Bluetooth folder, or can I capture it within the app?

Either way how can I throw up an alert message saying waiting for file, and when the file is received remove the alert. I don't thing STATE_CONNECTING refers to this either because the state never changes during this process.

Currently I have a while loop with a timeout waiting while file doesn't exists.... Terrible I know.



Solution 1:[1]

Are you using BluetoothChat sample ?

STATE_CONNECTING refers to the moment when you found a device and you are trying to connect. To download a file, you will have to open a BluetoothSocket and in BluetoothChat sample, you will be in STATE_CONNECTED when the socket is open.

You can display an alert message at the very beginning of ConnectedThread, before reading in the InputStream, and cancel it in the InputStream loop, when the file is received. You can also implement a timeout if the file is never send.

I'm not sure to understand your needs, but, you can also simply send the string with bluetooth, and save it on the second device in a File. It'll be easier to implement.

Hope it helps

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Skaard-Solo