Pankaj Singhal
Pankaj Singhal

Reputation: 16053

Automatically turn off Bluetooth after sending files

I am creating an application allowing a user to use Bluetooth in it. Also I'm programmatically changing the name of the Bluetooth device so that users can easily find out who all persons are using the same application. I just want to ask that is there some way to automatically turn-off the Bluetooth device once the bluetooth has finished sending/receiving files to/from the other person?? As I'll have to change the device name back to original, I'm thinking of doing it when the files are sent.And turn off Bluetooth also.

If not possible for both is it possible of atleast one??
By the way, Right now i'm using startActivityForResult() to turn off the bluetooth but the Bluetooth sends files in background process and my activity finished as soon as it starts sending files & bluetooth turns off.
Any help Appreciated.

Upvotes: 2

Views: 640

Answers (1)

Girija Patil
Girija Patil

Reputation: 430

 BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();    
    if (!mBluetoothAdapter.isEnabled()) {

        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

         ********** Here File send code***********

       mBluetoothAdapter.disable();
    }

Upvotes: 2

Related Questions