SoFunction
Updated on 2025-03-02

Android 6.0 Bluetooth cannot search for device, MIUI permission application mechanism method

To provide higher data protection, permissions about Wifi and Bluetooth are added on Android 6.0.

The device needs to be searched for Bluetooth to use positioning services, so in development targetSdkVersion is greater than or equal to 23 (6.0) and permissions are required in the code.

Two permissions are required in the configuration file:

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

When calling in the code, make permission judgment first. If there is no permission, apply for permission:

private void requestPermission() {
 if (.SDK_INT &gt;= 23) {
  int checkAccessFinePermission = (this, .ACCESS_FINE_LOCATION);
  if (checkAccessFinePermission != PackageManager.PERMISSION_GRANTED) {
   (this, new String[]{.ACCESS_FINE_LOCATION},
     REQUEST_PERMISSION_ACCESS_LOCATION);
   (TAG, "No permission, request permission");
   return;
  }
  (TAG, "Already have targeting permissions");
 }
 //Do what you should do}

There will be a callback after calling()

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
 switch (requestCode) {
  case Common.REQUEST_PERMISSION_ACCESS_LOCATION: {
   if ( &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    (TAG, "Enable permission granted!");
    //Do what you should do   } else {
    (TAG, "No positioning permission, please enable it first!");
   }
  }
 }
 (requestCode, permissions, grantResults);
}

Some people on the Internet say that when the permission confirmation box pops up, the user clicks confirm or rejects, it will only call back: onRequestPermissionsResult

But this is not the case with Xiaomi mobile phone MIUI. The MIUI is as follows: The permission management sets the application's positioning permission to reject or ask when checkAccessFinePermission != PackageManager.PERMISSION_GRANTED, which means there is no positioning permission. If set to allow, checkAccessFinePermission ==PackageManager.PERMISSION_GRANTED, indicating that there is positioning permission.

When setting rejection, no permission use confirmation box pops up, but a callback is directly: no permissions

When setting the query, the permissions use confirmation box does not pop up, but a callback is directly called: you already have permissions, and then a confirmation box pops up when calling the Bluetooth code. When clicking Allow, permission management becomes allowed. When clicking Deny, permission management becomes reject, but when you clicking Deny, permission management becomes reject, but when you perform permission check again, you will return to the existing positioning permission. The permission management is obviously rejected, so why do you have positioning permissions? I feel that this is a bug in MIUI. My system is: MIUI 8 6.11.3 development version.

The above article Android 6.0 Bluetooth cannot search for the device. The MIUI permission application mechanism method is all the content I share with you. I hope you can give you a reference and I hope you can support me more.