Reputation: 57
I'm developing an android app that allows the user to control the central locking system of his vehicle, thus eliminating the need of the small remote key tag. But According to what I have done so far, everytime the user opens the app, his phone bluetooth has to be turned on manually, as in it asks for the users permission.
So what I need to know is, is there a way to turn on the phone bluetooth adapter programmatically, so that everytime the app is launched, the phone bluetooth will be enabled automatically.
I hope my question is clear. I'm new to the android programming field.
P.s - If you're wondering how the communication between the phone and the vehicle is done, there are some circuits and a bluetooth module connected to a microcontroller in the vehicle.
Upvotes: 4
Views: 4473
Reputation: 107
In addition to SoulRayder's code
You will need to add a uses permission in the AndroidManifest.xml file under app >
manifests.
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
This goes before the <application>
tag but inside the <manifest>
tag
Upvotes: 0
Reputation: 5166
Yes this is possible.
btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter == null)
{
// Device does not support Bluetooth
Toast.makeText(getApplicationContext(), "Device does not support bluetooth", Toast.LENGTH_LONG).show();
}
else
{
if (!btAdapter.isEnabled())
{
btAdapter.enable();
Toast.makeText(getApplicationContext(), "Bluetooth switched ON", Toast.LENGTH_LONG).show();
}
Upvotes: 6