3

I want to build a Android application that interacts with my BT device and wakes him.

  • The device and the phone are paired
  • The device constantly scans for the specific phone and requests connection every time the phone is in range.

I want to know is it possible for my application to get notified every time the device asks for connection. Take into consideration that the application is not active.

For example, when i get into the car it connects automatically to my car BT and when i get call, the call application is activated? (but maybe that's something that Android internally does...)

Any ideas?

user733284
  • 925
  • 2
  • 11
  • 18

1 Answers1

9

Yes you can get notified when a new device is connected using Broadcast receiver. Please refer to the code below.

BroadcastReceiver btReceive=new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

        if (BluetoothDevice.ACTION_FOUND.equals(action)) {
           //the device is found
         }
    }
};
Ben Pearson
  • 7,532
  • 4
  • 30
  • 50
SREEJITH
  • 816
  • 1
  • 8
  • 19
  • 1
    Which is the action you are binding the BroadcastReceiver to? This is the main question – StErMi Sep 02 '14 at 10:55
  • 1
    if (BluetoothDevice.ACTION_FOUND.equals(action)) and BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)and BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) – stefan Nov 01 '14 at 15:59
  • 2
    its working in my project... but when i exit my application then its not working. i want to notification when ever i connect device its show. if app is open or close – tej shah Aug 24 '15 at 09:18