user3676154
user3676154

Reputation: 9

switching bluetooth on and off in Android app

If an Android app wants to access bluetooth, does it have to explicitly ask the user to switch bluetooth on? Could the user authorise the app to switch it on (and off) whenever it wants?

Upvotes: 1

Views: 180

Answers (1)

Vilen
Vilen

Reputation: 5061

NO need to ask switch it you manually, you can just ask for permission also you need to add permissions in android manifest

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />

code for enabling BT

// enable device discovery - this will automatically enable Bluetooth
    Intent discoveryIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    discoveryIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, DISCOVER_DURATION);
    startActivityForResult(discoveryIntent, REQUEST_BLU);

Upvotes: 2

Related Questions