Reputation: 5
I want to create bluetooth android app such that when it gets disconnected from the connected device it beeps an audio. I used the following code
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
this.registerReceiver(mReceiver, filter);
But in these cases if any one of the devices(two) is taken away a 1cm it beeps i want it to beep atleast when any of the device crosses the range of bluetooth?????
Thanks in advance
Upvotes: 0
Views: 1106
Reputation: 251
ToneGenerator toneGen = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
this.registerReceiver(mReceiver, filter);
mReceiver = 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)) {
//Device found
}
else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
//Device is now connected
toneGen.stopTone(); // Stop alarm / beep when connected again
}
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
//Done searching
}
else if (BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) {
//Device is about to disconnect
}
else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
//Device has disconnected
toneGen.startTone(ToneGenerator.TONE_CDMA_ONE_MIN_BEEP)
}
}
};
Upvotes: 0