1. Are you ready for the Galaxy S20? Here is everything we know so far!

Permanently remove discoverability check while turning ON/OFF BlueTooth on Android

Discussion in 'Android Development' started by Lubron, Dec 22, 2019.

  1. Lubron

    Lubron Lurker
    Thread Starter

    Hi everyone!

    I'm developing an Android app that is thinked to run for long periods of time. At certain moments I need to communicate with some Blutooth devices (both 3.0 and BLE) so the idea is to switch ON the BlueTooth when I need and then turning it OFF for the rest of time.

    My problem come when I turn the BT ON and an alert always pops us saying about the discoverability of my device, and I wish to remove this alert.

    Searching around for a solution, I tried using intents :

    Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
    startActivityForResult(discoverableIntent, GlobalConfiguration.REQUEST_DISCOVERABLE);


    and also reflection:

    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    Method method;
    try {

    method = bluetoothAdapter.getClass().getMethod("setScanMode", int.class, int.class);
    method.invoke(bluetoothAdapter, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, 0);
    }
    catch(Exception e) {

    e.printStackTrace();
    }


    both unsuccessfully, standing that after BT state switch from ON -> OFF -> ON, the dialog about the discoverability comes up again.

    There's a way to remove this alert forever, also after an ON/OFF of the BlueTooth?!

    Thanks in advance
     

    Advertisement

Loading...
Similar Threads - Permanently remove discoverability
  1. Year1917
    Replies:
    9
    Views:
    461
  2. Lesa smallwood
    Replies:
    1
    Views:
    240
  3. Lesa smallwood
    Replies:
    3
    Views:
    302
  4. Phrozt
    Replies:
    1
    Views:
    183
  5. Cyberdev
    Replies:
    2
    Views:
    859
  6. ASPyr97
    Replies:
    3
    Views:
    1,499
  7. brick6515
    Replies:
    6
    Views:
    533
  8. kurtisane
    Replies:
    1
    Views:
    321
  9. ukchy
    Replies:
    5
    Views:
    507
  10. anon125
    Replies:
    6
    Views:
    980

Share This Page

Loading...