0

Okay, I've searched online a lot for this but can't seem to find the exact issue I'm facing. I have a brand new Galaxy A7 phone that came with Android 7.0 on it.

I'm trying to turn on Bluetooth through an app I created and set it discoverable permanently (i.e, not only 2 minutes). Here is the code I use:

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivity(discoverableIntent);

But on the prompt message, I'm getting a 120 seconds limit. I've played with this, writing 999 and 99 and many other numbers but I always get the same prompt for 120 seconds. I've looked around and read in a thread that it's probably something with the bluetooth's settings file but I can't seem to find it.

Anyone knows why this piece of code (which works on android 8.0 and 5.2) doesn't seem to work and how to fix it? Thanks :)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Dan Baruch
  • 1,063
  • 10
  • 19
  • Possibly of interest: https://stackoverflow.com/questions/28035731/android-set-bluetooth-discoverability-unbounded#comment72637908_29182157 – stkent Jun 12 '18 at 14:16
  • Also, from https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#ACTION_REQUEST_DISCOVERABLE: "The sender of this Intent can optionally use extra field EXTRA_DISCOVERABLE_DURATION to request the duration of discoverability. Currently the default duration is 120 seconds, and maximum duration is capped at 300 seconds for each request." If you try 300 seconds, does that work on 7.0? – stkent Jun 12 '18 at 14:17
  • @stkent nope. I tried with 0, 1, 15, 200, 300. All produces 120 seconds on prompt. I've found out that if I delete all BT's cache, the next time I try to activate it I can just once change the 120 seconds limit. How ever, it still can't be 0. When I try to put 0 it just jumps back to 120 seconds prompt. Check the piece of code I've provided, I am using the EXTRA_DISCOVERABLE_DURATION flag but it's as if the system completely ignores it's value. – Dan Baruch Jun 12 '18 at 14:29

0 Answers0