How to remove the dialog window that asks the user to allow bluetooth visibility on Android ?

This dialog contains the following message : « An app wants to make your device visible to other Bluetooth devices… »

if you look in the code you’ll see that this dialog is related to the Settings application, particularly RequestPermissionActivty.java. You’ll see also that a boolean can automatically click on the yes button, exactly what we need:

   if (getResources().getBoolean(R.bool.auto_confirm_bluetooth_activation_dialog) == true) {
           // dismiss dialog immediately if settings say so
           onClick(null, DialogInterface.BUTTON_POSITIVE);
   }

So the trick is to find where is this boolean. It is quite obvious and it must be in the res folder in the bools file. So looking in packages/apps/Settings/res/values/bools.xml we find what we need:

 <!-- Whether the bluetooth activation confirmation dialogs should be auto dismissed.
        Can be overridden for specific product builds. -->
 <bool name="auto_confirm_bluetooth_activation_dialog">false</bool>

switching the value to true and the trick is done.

Enjoy !