1

I would like to create a bluetooth app.. when I click the app it will show a dialogue box asking for permission to turn on bluetooth and scan for devices.

I am very new to android programming and I dont know java language.I just learn by watching youtube videos.I need to learn for my school project.I have learned how to make dialogue boxes and button using eclipse but I'm not sure how to turn on bluetooth and scan for device instantaneously when I open the app.I found that there are tutorials on bluetooth where the user have to press buttons so that the bluetooth will turn on and scan on press of button.

Someone please help me.

Thank you

Lal
  • 14,505
  • 4
  • 39
  • 63
Yokes
  • 11
  • 3

2 Answers2

1

You can enable the bluetooth as follows..

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
mBluetoothAdapter.enable(); 

And see this link to search for devices in range..

One answer in that link says..

To start search

mBluetoothAdapter.startDiscovery(); 
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

To find devices

    if (BluetoothDevice.ACTION_FOUND.equals(action)) 
    {
        // Get the BluetoothDevice object from the Intent
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        // Add the name and address to an array adapter to show in a ListView
       mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
    }
  }
};

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
registerReceiver(mReceiver, filter);

To start all these functions whenever the app is launched just put these codes inside onCreate()

Try it...

Community
  • 1
  • 1
Lal
  • 14,505
  • 4
  • 39
  • 63
0

I would suggest to do a little bit more research on that because your question is quite basic and simple to sort out.

Start checking Android's Bluetooth reference and here you will find exactly what you need.

http://developer.android.com/guide/topics/connectivity/bluetooth.html

Moreover, on the right side of the guide you have a couple of links to Bluetooth example projects. As I said, start checking it and try to write you app, you will find it very easy and simple.

GoRoS
  • 4,445
  • 2
  • 37
  • 57