0
## How I solved it:
### For Permissions: Make sure to request Background location too:

```Java
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

For Verifying Permissions:

Copy the whole snippet from: https://altbeacon.github.io/android-beacon-library/requesting_permission.html to your on create method

BE PATIENT!!!!

Apparently, it takes about 1 minute for the first detection (both monitoring and ranging) to occur despite me setting the ranging time to 5 seconds (5000 ms). After that, the response time for out of range beacon should be less than half a second.

Please Advice if you can help with the long waiting time between starting the monitoring to receiving a list of beacons detected despite a change in beacon detection state already within 1 second of starting monitoring.

Original Question

Extra Detail: The detection goes smoothly even if the 'Change Bluetooth Permission' mentioned above is set to 'notify' whenever I switch to another app despite the app not being a service. Why is that?

Original Question: I am trying to scan for beacons around me using the android beacons library and it never works unless I manually go into settings -> manage apps and change the 'Change Bluetooth Connectivity (turn Bluetooth on or off)' permission from 'notify' -> to 'Accept'

However, I already requested bluetooth and bluetooth admin permissions

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

as well as other permissions like fine location/coarse location

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

The previous app that I created worked fine on my device but in that app, the beacon functions are built as a 'service' and I have heard that requesting Location permission when running beacon functions not as a service can spell disaster. However, removing the location permissions did not make a difference upon my experimentation. It is only manually changing the bluetooth permission in settings that made it work.

So the question is, how to I force the general bluetooth permission on a Xiaomi phone to ACCEPT through a prompt like requesting dangerous permissions for coarse location requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1234); and is this the right way to solve the issue? Many thanks

Device: Xiaomi Mi8 (MIUI11 Android 10 API29)```

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Someone please help me fix the formatting errors. Stack Overflow is acting weird and always complains that I have code that isn't formatted properly and doesn't allow me to save so I just made the whole paragraph code to save my time. – Clement Tong Jun 27 '20 at 10:45
  • If you have solved your own question you should put the answer in the answer block for clarity. You can accept your own answer after 24 hours. – davidgyoung Jun 27 '20 at 12:06
  • Hi, how did you solve the problem? – Matt39 Sep 29 '20 at 14:38
  • @Matt39 So recently, the issue seems to be resolved. The waiting stage is only about 0.2 seconds and during that stage, when beacons are detected by the change in state method I set the text to initialising. After about 0.2 seconds, when a beacon is ranged, the text box changes to show the number of beacons in range in my app, and it works fine. Don't know what I changed though. – Clement Tong Sep 30 '20 at 15:03

0 Answers0