With the following code you can pop up a window with bluetooth acces request:
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
The output of the code is the following image:
Is it possible to change the message (so not "An app wants to turn on Bluetooth", but something like "Hey can you please turn on Bluetooth?"
You should create your own dialog with your own message and then call
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.enable();
And do not forget to declare the BLUETOOTH_ADMIN permission in your manifest.
Anyway, this operation is discouraged... The enable() method is provided only for applications that include a user interface for changing system settings, such as a "power manager" app.
No, this is build-in Android functionality, so you would have to make a custom dialog which asks the question the way you want.
Then you would enable or disable Bluetooth programmatically based on what the users choice was.
Related
Hello we are using bluetooth in Android.
When we turn on bluetooth it give us default dialog "An app wants to turn on Bluetooth" with Deny and Allow buttons. With this message a blue line is shown behind that dialog which is nothing but a text "Bluetooth Permission". Can we hide or remove this message behind the dialog. I have attached screenshots of the page.
Here is the code Snippet
if (!mBluetoothAdapter.isEnabled()) {
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
}
I am trying to use BluetoothAdapter with ACTION_REQUEST_DISCOVERABLE to discover my phone to other users according to this:
testIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivity(testIntent);
I get the dialog box of Bluetooth Permission Request, but for some reason I can't see it on my activity. I can see it only when I exit this program. I want to override the menu in that dialog.
Can I do it , if so , how can I change it ? And why can't I see it on the activity I am in it ?
I have a requirement where I want to develop a hybrid application and list the Bluetooth devices, scan and connect, share files etc.
So I want to add BluetoothAdapter mAdapter value into extras and pass it into onActivity result. Like enableIntent.putExtra("", mAdapter); and use it in onActivityResult by getExtra(...). Is there a way to do so??..
if (!mBluetoothAdapter.isEnabled()) {
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
((Activity)context).startActivityForResult(enableIntent, RequestCodes.BLUETOOTH_ENABLE_CODE);
}
Why don't you use Application class to store that data and use wherever you need.
Check this post for how to use Application class.
I have the code that enables the blueooth on a device.
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, 1);
I am wondering how can I disable it?
Take a look at BluetoothAdapter.disable() function. You should ask a user before disabling bluetooth though.
Don't forget to add next permission to your AndroidManifest.xml :
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
I managed to use .disable and .enable with the BLUETOOTH_ADMIN permission.
I am trying to get my Activity to enable Bluetooth with the Android 2.0.1 SDK, I am using some code straight from the documentation here: http://developer.android.com/guide/topics/wireless/bluetooth.html
Which is:
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
I get an error at the REQUEST_ENABLE_BT part where Eclipse says it cannot be resolved. What am I doing wrong?
The REQUEST_ENABLE_BT part is a request code that you should handle in your onActivityResult method. In that method you'll be notified whether or not enabling Bluetooth was successful.
In that code snippet they didn't show the definition of it, but it's just a constant integer so you can set it to any value you like.
See the documentation for startActivityForResult for more info about getting results back from activity launches.