mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-24 04:40:56 +03:00
Fix Bluetooth receiver
This commit is contained in:
parent
5772c231f6
commit
e9a5cc87ca
@ -5,7 +5,7 @@
|
||||
a:versionCode="47"
|
||||
a:versionName="1.3.0.7">
|
||||
|
||||
<uses-permission a:name="android.permission.INTERNET"/>
|
||||
<uses-permission a:name="android.permission.INTERNET"/>
|
||||
<uses-permission a:name="android.permission.READ_PHONE_STATE"/>
|
||||
<uses-permission a:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission a:name="android.permission.WAKE_LOCK"/>
|
||||
@ -13,6 +13,7 @@
|
||||
<uses-permission a:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission a:name="android.permission.RECORD_AUDIO"/>
|
||||
<uses-permission a:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
|
||||
<uses-permission a:name="android.permission.BLUETOOTH"/>
|
||||
|
||||
<uses-sdk
|
||||
a:minSdkVersion="14"
|
||||
@ -68,7 +69,8 @@
|
||||
<activity
|
||||
a:name=".activity.DownloadActivity"
|
||||
a:configChanges="keyboardHidden"
|
||||
a:launchMode="singleTask"/>
|
||||
a:launchMode="singleTask"
|
||||
a:exported="true" />
|
||||
<activity
|
||||
a:name=".activity.SettingsActivity"
|
||||
a:configChanges="orientation|keyboardHidden"
|
||||
@ -132,8 +134,8 @@
|
||||
</receiver>
|
||||
<receiver a:name=".receiver.BluetoothIntentReceiver">
|
||||
<intent-filter>
|
||||
<action a:name="android.bluetooth.device.action.ACL_CONNETED"/>
|
||||
<action a:name="android.bluetooth.device.action.ACL_DISCONNETED"/>
|
||||
<action a:name="android.bluetooth.device.action.ACL_CONNECTED"/>
|
||||
<action a:name="android.bluetooth.device.action.ACL_DISCONNECTED"/>
|
||||
<action a:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED"/>
|
||||
<action a:name="android.bluetooth.a2dp.action.SINK_STATE_CHANGED"/>
|
||||
</intent-filter>
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user