Merge "Add APIs to get remote device's battery level (1/2)"
am: ceaccbfe70
Change-Id: Ic3253ef666632aaaffe8e1547dc563cd3bca9e37
This commit is contained in:
@@ -202,6 +202,34 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
public static final String ACTION_BOND_STATE_CHANGED =
|
public static final String ACTION_BOND_STATE_CHANGED =
|
||||||
"android.bluetooth.device.action.BOND_STATE_CHANGED";
|
"android.bluetooth.device.action.BOND_STATE_CHANGED";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcast Action: Indicates the battery level of a remote device has
|
||||||
|
* been retrieved for the first time, or changed since the last retrieval
|
||||||
|
* <p>Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
|
||||||
|
* #EXTRA_BATTERY_LEVEL}.
|
||||||
|
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||||
|
public static final String ACTION_BATTERY_LEVEL_CHANGED =
|
||||||
|
"android.bluetooth.device.action.BATTERY_LEVEL_CHANGED";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used as an Integer extra field in {@link #ACTION_BATTERY_LEVEL_CHANGED}
|
||||||
|
* intent. It contains the most recently retrieved battery level information
|
||||||
|
* ranging from 0% to 100% for a remote device, {@link #BATTERY_LEVEL_UNKNOWN}
|
||||||
|
* when the valid is unknown or there is an error
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_BATTERY_LEVEL =
|
||||||
|
"android.bluetooth.device.extra.BATTERY_LEVEL";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used as the unknown value for {@link #EXTRA_BATTERY_LEVEL} and {@link #getBatteryLevel()}
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int BATTERY_LEVEL_UNKNOWN = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used as a Parcelable {@link BluetoothDevice} extra field in every intent
|
* Used as a Parcelable {@link BluetoothDevice} extra field in every intent
|
||||||
* broadcast by this class. It contains the {@link BluetoothDevice} that
|
* broadcast by this class. It contains the {@link BluetoothDevice} that
|
||||||
@@ -860,6 +888,27 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the most recent identified battery level of this Bluetooth device
|
||||||
|
* <p>Requires {@link android.Manifest.permission#BLUETOOTH}
|
||||||
|
*
|
||||||
|
* @return Battery level in percents from 0 to 100, or {@link #BATTERY_LEVEL_UNKNOWN} if
|
||||||
|
* Bluetooth is disabled, or device is disconnected, or does not have any battery
|
||||||
|
* reporting service, or return value is invalid
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||||
|
public int getBatteryLevel() {
|
||||||
|
if (sService == null) {
|
||||||
|
Log.e(TAG, "Bluetooth disabled. Cannot get remote device battery level");
|
||||||
|
return BATTERY_LEVEL_UNKNOWN;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return sService.getBatteryLevel(this);
|
||||||
|
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
||||||
|
return BATTERY_LEVEL_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the bonding (pairing) process with the remote device.
|
* Start the bonding (pairing) process with the remote device.
|
||||||
* <p>This is an asynchronous call, it will return immediately. Register
|
* <p>This is an asynchronous call, it will return immediately. Register
|
||||||
|
|||||||
@@ -227,14 +227,13 @@ public final class BluetoothHeadset implements BluetoothProfile {
|
|||||||
*
|
*
|
||||||
* <p>This intent will have 3 extras:
|
* <p>This intent will have 3 extras:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li> {@link #EXTRA_IND_ID} - The Assigned number of headset Indicator which is supported by
|
* <li> {@link #EXTRA_HF_INDICATORS_IND_ID} - The Assigned number of headset Indicator which
|
||||||
the headset ( as indicated by AT+BIND
|
* is supported by the headset ( as indicated by AT+BIND command in the SLC
|
||||||
command in the SLC sequence).or whose value
|
* sequence).or whose value is changed (indicated by AT+BIEV command) </li>
|
||||||
is changed (indicated by AT+BIEV command)</li>
|
* <li> {@link #EXTRA_HF_INDICATORS_IND_VALUE}- The updated value of headset indicator. </li>
|
||||||
* <li> {@link #EXTRA_IND_VALUE}- The updated value of headset indicator. </li>
|
|
||||||
* <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li>
|
* <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>{@link #EXTRA_IND_ID} is defined by Bluetooth SIG and each of the indicators are
|
* <p>{@link #EXTRA_HF_INDICATORS_IND_ID} is defined by Bluetooth SIG and each of the indicators are
|
||||||
* given an assigned number. Below shows the assigned number of Indicator added so far
|
* given an assigned number. Below shows the assigned number of Indicator added so far
|
||||||
* - Enhanced Safety - 1
|
* - Enhanced Safety - 1
|
||||||
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to
|
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ interface IBluetooth
|
|||||||
ParcelUuid[] getRemoteUuids(in BluetoothDevice device);
|
ParcelUuid[] getRemoteUuids(in BluetoothDevice device);
|
||||||
boolean fetchRemoteUuids(in BluetoothDevice device);
|
boolean fetchRemoteUuids(in BluetoothDevice device);
|
||||||
boolean sdpSearch(in BluetoothDevice device, in ParcelUuid uuid);
|
boolean sdpSearch(in BluetoothDevice device, in ParcelUuid uuid);
|
||||||
|
int getBatteryLevel(in BluetoothDevice device);
|
||||||
|
|
||||||
boolean setPin(in BluetoothDevice device, boolean accept, int len, in byte[] pinCode);
|
boolean setPin(in BluetoothDevice device, boolean accept, int len, in byte[] pinCode);
|
||||||
boolean setPasskey(in BluetoothDevice device, boolean accept, int len, in byte[]
|
boolean setPasskey(in BluetoothDevice device, boolean accept, int len, in byte[]
|
||||||
|
|||||||
@@ -146,6 +146,7 @@
|
|||||||
<protected-broadcast android:name="android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL" />
|
<protected-broadcast android:name="android.bluetooth.device.action.CONNECTION_ACCESS_CANCEL" />
|
||||||
<protected-broadcast android:name="android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST" />
|
<protected-broadcast android:name="android.bluetooth.device.action.CONNECTION_ACCESS_REQUEST" />
|
||||||
<protected-broadcast android:name="android.bluetooth.device.action.SDP_RECORD" />
|
<protected-broadcast android:name="android.bluetooth.device.action.SDP_RECORD" />
|
||||||
|
<protected-broadcast android:name="android.bluetooth.device.action.BATTERY_LEVEL_CHANGED" />
|
||||||
<protected-broadcast android:name="android.bluetooth.devicepicker.action.LAUNCH" />
|
<protected-broadcast android:name="android.bluetooth.devicepicker.action.LAUNCH" />
|
||||||
<protected-broadcast android:name="android.bluetooth.devicepicker.action.DEVICE_SELECTED" />
|
<protected-broadcast android:name="android.bluetooth.devicepicker.action.DEVICE_SELECTED" />
|
||||||
<protected-broadcast
|
<protected-broadcast
|
||||||
|
|||||||
Reference in New Issue
Block a user