Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open the Bluetooth Settings Activity programmatically?

I want to open bluetooth settings on button click like this see imagebluetooth 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);             }         }); 
like image 616
Mahesh Avatar asked Dec 17 '12 09:12

Mahesh


People also ask

How do I get to programmatically in Android settings?

To achieve this just use an Intent using the constant ACTION_SETTINGS, specifically defined to show the System Settings: startActivity(new Intent(Settings. ACTION_SETTINGS));

How do I access Bluetooth menu?

Swipe down from the top of the screen. Touch and hold Bluetooth . If your accessory is listed under "Available media devices," next to your device's name, tap Settings . If no accessories are listed under "Previously connected devices," tap See all.


2 Answers

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.

like image 174
Ewoks Avatar answered Oct 22 '22 23:10

Ewoks


I think you should try this easier one :

startActivity(new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS)); 
like image 39
Aj 27 Avatar answered Oct 23 '22 01:10

Aj 27