4

I am writing an app that requires Bluetooth to be enabled to use and there is a strange "title like" set of text that appears behind the alert dialog that asks to enable Bluetooth. The text says "Bluetooth Permission Request" in big bold letters and once the alert dialog disappears this text does as well like half a second later. Anyone know why this text is popping up and or how to get rid of it?

Here's my code that sets up the intent.

private void ensureBluetoothEnabled() {
    switch (mRxBleClient.getState()) {
        case BLUETOOTH_NOT_ENABLED:
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
            break;
        case READY:
            showScanFragment();
    }
}

And this is the code that runs after.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == REQUEST_ENABLE_BT) {
        if(RESULT_OK == resultCode)
            showScanFragment();
        else
            new AlertDialog.Builder(this).setMessage("Bluetooth is required to use this service.")
                    .setPositiveButton("OK", (dialog, which) -> {
                        ensureBluetoothEnabled();
                        dialog.dismiss();
                    });
    }
}

enter image description here

enter image description here

Permissions code

private static final int REQUEST_PERMISSIONS = 10;

private static final String[] PERMISSIONS = new String[]{
        Manifest.permission.BLUETOOTH,
        Manifest.permission.BLUETOOTH_ADMIN,
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    ((MainApplication) getApplication()).getRxBleClientComponent().inject(this);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    requestPermissions(PERMISSIONS, REQUEST_PERMISSIONS);
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    for(int i : grantResults)
        if(i == PackageManager.PERMISSION_DENIED) {
            Toast.makeText(this, "All permissions are required. App will close.", Toast.LENGTH_LONG).show();
            finish();
            return;
        }

    ensureBluetoothEnabled();
}
11
  • 1
    can you attach an image to better describe your issue? Sep 14, 2017 at 13:46
  • Just added them. Sep 14, 2017 at 13:56
  • What api level is your device one? I think the issue is, it's generating a permission request to allow the app to use Bluetooth. Sep 14, 2017 at 13:57
  • Target and compile SDK are 25 and my Android version is 7.1.1 Sep 14, 2017 at 14:01
  • As a test, try requesting permission to use Bluetooth explicitly before requesting to enable Bluetooth then once you get permission try enabling the Bluetooth and see if you still have that dialog box appear. Sep 14, 2017 at 14:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.