priyanka ... priyanka ... - 1 year ago 80
Android Question

Can I disable Bluetooth or camera or wifi of android device and allow enabling only through my customized app?

Below is the code for enabling/disabling but it does not disable the device settings.

I want to know how to disable bluetooth(Camera/Wifi) facility of android device and enable it only through my customized app. User should be able to on the bluetooth only through our app.

BluetoothAdapter bluetoothAdapter = BluetoothAdapter
boolean isEnabled = bluetoothAdapter.isEnabled();
if (isEnabled) {
Toast.makeText(getApplicationContext(), "Enabled",
} else {
Toast.makeText(getApplicationContext(), "Not Enabled",

Answer Source

You need to implement BroadcastReceiver that listens to BluetoothAdapter.ACTION_STATE_CHANGED (link). It should disable it back and show some information about your lock to user.

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();

        if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
            final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
            switch (state) {
            case BluetoothAdapter.STATE_OFF:
                //do nothing
            case BluetoothAdapter.STATE_TURNING_OFF:
                //do nothing
            case BluetoothAdapter.STATE_ON:
                //disable it
            case BluetoothAdapter.STATE_TURNING_ON:
                //do nothing

This is a bit hacky, but this is the best you can do - like I wrote previously there is no way to disable this switch in Settings, as Settings are separate application and you cannot modify it, just like other apps cannot modify your application.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download