Bluetooth discoverable problem! (Android)


#1

Hi,
I am trying to make an application, that when started makes the bluetooth discoverable. For that I am using the code

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter != null)
    {
        if (!mBluetoothAdapter.isEnabled())
        {
            mBluetoothAdapter.enable();
         }
         if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE)
            {
                Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
                discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
                startActivityForResult(discoverableIntent, 1001);
            }
    }

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1001)
        {
            Toast.makeText(CameraActivity.this, "Device is discoverable now!", Toast.LENGTH_SHORT).show();
        }
    }

when this code run for the first time, the apps asks complete action using :

  1. Bluetooth Permission Request
    com.android.settings
  2. Bluetooth Permission Request
    com.android.tv.settings

when I select the first one the app prompts “An app wants to make the media box visbile to other bluetooth devices for 300 seconds” with buttons deny and allow.
If I allow it, the app closes and when I start the app within that 300 seconds the app works perfectly. I don’t want this popup to appear and want that the app automatically makes the device discoverable.

when I select the second one the screen flashes and nothing happens and when I click back on the app again the screen flashes and the app does not start.

If I remove this code all together, the app works normally.


#2

bake your own rom to get rid of the dialog.


#3

Alright, how would I go about doing that?