Android 6.0 Bluetooth search can not find the device reason MIUI permission application mechanism method

  • 2021-09-24 23:42:22
  • OfStack

Permissions on Wifi and Bluetooth have been added on Android 6.0 to provide greater data protection.

Bluetooth search to the device needs to use location services, so in the development of targetSdkVersion greater than or equal to 23 (6.0) requires access in the code

You need to apply for two permissions in the configuration file:


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

When calling in the code, judge the permission first, and apply for permission if there is no permission:


private void requestPermission() {
 if (Build.VERSION.SDK_INT >= 23) {
  int checkAccessFinePermission = ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
  if (checkAccessFinePermission != PackageManager.PERMISSION_GRANTED) {
   ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
     REQUEST_PERMISSION_ACCESS_LOCATION);
   Log.d(TAG, " No permission, request permission ");
   return;
  }
  Log.d(TAG, " You already have location permissions ");
 }
 // Do the following things to do 
}

There will be 1 callback after calling ActivityCompat. requestPermissions ()


@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
 switch (requestCode) {
  case Common.REQUEST_PERMISSION_ACCESS_LOCATION: {
   if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    Log.d(TAG, " Open permissions permission granted!");
    // Do the following things to do 
   } else {
    Log.d(TAG, " There is no location permission, please open it first !");
   }
  }
 }
 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

Some people on the Internet say that when the permission confirmation box pops up, the user will call the callback when he clicks OK or reject: onRequestPermissionsResult

But this is not the case on Xiaomi mobile phone MIUI. On MIUI, this is the case: Permission management where setting the application's location permission to reject or ask checkAccessFinePermission! = PackageManager.PERMISSION_GRANTED, indicating no location permission. If set to Allow, checkAccessFinePermission ==PackageManager.PERMISSION_GRANTED indicates that you have location permission.

Go to ActivityCompat. requestPermissions when setting rejection, and the permission use confirmation box does not pop up, but directly calls back: No permission

Go to ActivityCompat. requestPermissions when setting the query, and do not pop up the permission use confirmation box, but directly call back: existing permission, and then pop up the confirmation box when calling Bluetooth code. When you click Allow, Permission Management becomes Allow, and when you click Deny, Permission Management becomes Deny, but the next time you check the permissions, you return the existing location permissions. Authority management is obviously rejected there, how can there be positioning authority? It feels like this is an bug of MIUI, and my system is: MIUI 86.11.3 development version.


Related articles: