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 :
- Bluetooth Permission Request
com.android.settings - 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.