diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2934db99..b3dc4445 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -5,7 +5,7 @@ a:versionCode="47" a:versionName="1.3.0.7"> - + @@ -13,6 +13,7 @@ + + a:launchMode="singleTask" + a:exported="true" /> - - + + diff --git a/src/com/thejoshwa/ultrasonic/androidapp/receiver/BluetoothIntentReceiver.java b/src/com/thejoshwa/ultrasonic/androidapp/receiver/BluetoothIntentReceiver.java index 049b5200..9c75d3ac 100644 --- a/src/com/thejoshwa/ultrasonic/androidapp/receiver/BluetoothIntentReceiver.java +++ b/src/com/thejoshwa/ultrasonic/androidapp/receiver/BluetoothIntentReceiver.java @@ -18,6 +18,7 @@ */ package com.thejoshwa.ultrasonic.androidapp.receiver; +import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -40,25 +41,22 @@ public class BluetoothIntentReceiver extends BroadcastReceiver public void onReceive(Context context, Intent intent) { int state = intent.getIntExtra("android.bluetooth.a2dp.extra.SINK_STATE", -1); + BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); String action = intent.getAction(); + String name = device != null ? device.getName() : "None"; - Log.d(TAG, "Bluetooth Sink State: " + state); - Log.d(TAG, "Bluetooth Action: " + action); + Log.d(TAG, String.format("Sink State: %d; Action: %s; Device: %s", state, action, name)); boolean actionConnected = false; boolean actionDisconnected = false; - if (action != null) + if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { - if (action.equals(android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED)) - { - actionConnected = true; - - } - else if (action.equals(android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECTED) || action.equals(android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED)) - { - actionDisconnected = true; - } + actionConnected = true; + } + else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) || BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) + { + actionDisconnected = true; } boolean connected = state == android.bluetooth.BluetoothA2dp.STATE_CONNECTED || actionConnected; @@ -66,12 +64,13 @@ public class BluetoothIntentReceiver extends BroadcastReceiver if (connected) { - Log.i(TAG, "Connected to Bluetooth A2DP, requesting media button focus."); + Log.i(TAG, "Connected to Bluetooth device, requesting media button focus."); Util.registerMediaButtonEventReceiver(context); } - else if (disconnected) + + if (disconnected) { - Log.i(TAG, "Disconnected from Bluetooth A2DP, requesting pause."); + Log.i(TAG, "Disconnected from Bluetooth device, requesting pause."); context.sendBroadcast(new Intent(DownloadServiceImpl.CMD_PAUSE)); } }