How do I open the Bluetooth Settings Activity programmatically?
Solution 1
use
ComponentName cn = new ComponentName("com.android.settings",
"com.android.settings.bluetooth.BluetoothSettings");
instead of
final ComponentName cn = new ComponentName("com.android.settings",
"com.android.settings.bluetoothSettings");
to launch BluetoothSettings settings
Solution 2
Maybe I missed something but isn't this simpler future proof solution?
Intent intentOpenBluetoothSettings = new Intent();
intentOpenBluetoothSettings.setAction(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
startActivity(intentOpenBluetoothSettings);
It is definitely not possible to "remove" the other settings. On phones just one category of settings is shown. On tablets, because of some extra space, settings are shown in master-detail layout so there is no empty space on more the half of the tablet screen. This is how Android is designed and just by writing one app that can not be changed.
As suggested by @zelanix the BLUETOOTH_ADMIN
permission in manifest is required.
Solution 3
I think you should try this easier one :
startActivity(new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS));
Solution 4
If you want to open up the scan dialog (without leaving your app).
Intent bluetoothPicker = new Intent("android.bluetooth.devicepicker.action.LAUNCH");
startActivity(bluetoothPicker);
Solution 5
adb shell am start -a android.settings.BLUETOOTH_SETTINGS
Mahesh
Updated on July 28, 2022Comments
-
Mahesh almost 2 years
I want to open bluetooth settings on button click like this see image
HomeActivity.java
button.setOnClickListener(new OnClickListener() { public void onClick(View v) { final Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.bluetoothSettings"); intent.setComponent(cn); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity( intent); } });
-
Mahesh over 11 yearsbut is also display the other settings i want show only bluetooth settings all other must be hide
-
Mahesh over 11 yearsand i am use the android 4.0.3 tablet
-
ρяσѕρєя K over 11 years@AndroidNewc: this code for launching BluetoothSettings settings Activity and it's not possible i think to remove all other Options from Setting activity
-
zelanix about 10 yearsThis seems to be the better solution to me. Just a comment (this applies to both solutions) that this requires the
BLUETOOTH_ADMIN
permission. -
Ted about 10 yearsIs there any way to get this settings window to open 'non-modally' from your app? The only way to get back to the app was via the 'back' button next to the home button, rather than the two windows appearing separately in the 'task list' view of apps as I would have expected. (Perhaps this 'modal' method is the preferred, standard, technique though? Apologies, I'm a v new newb when it comes to Android as a user & developer)
-
Kevin Lam over 9 yearsTed, did you ever figure out a better way?
-
Totoro over 9 yearsThe question seems to be about doing it programmatically, not through command line.
-
Learn OpenGL ES almost 9 yearsThis should not require BLUETOOTH_ADMIN and doesn't on stock Android -- may be a manufacturer bug. I reported this one to Samsung.
-
Ewoks over 8 yearsIMHO this can crash with any new android version
-
lsrom almost 7 yearsThis is indeed correct answer. Tested on Android 5.0.
-
DukeDidntNukeEm over 6 yearsI think starting with sdk v23 / Android 6 you need at least <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> and perhaps the _ADMIN one as well
-
Johnny Five over 6 yearsWorks on API 26 (Android 8). "setAction" solution doesn't work on API 26.
-
Johnny Five over 6 yearsDoes't work on API 26 (android 8). No activity found to handle the intent ACTION_BLUETOOTH_SETTINGS. Accepted answer works on API 26.
-
bcr over 5 yearsandroid.settings.BLUETOOTH_SETTINGS works for me on Android 8.0.
-
Marcus Wolschon about 5 yearsIn Android "Q" we get Settings.Panel . developer.android.com/reference/android/provider/… It does not support bluetooth yet (just NFC) but this is something to look out for to "remove the other settings" and get just a Bluetooth ON/OFF -switch.
-
drindt over 3 yearsstartActivity(Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS))