We can now list supported bluetooth services
This commit is contained in:
@@ -7,7 +7,10 @@ import android.os.Parcelable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import uk.co.alt236.bluetoothlelib.device.adrecord.AdRecordStore;
|
||||
import uk.co.alt236.bluetoothlelib.resolvers.BluetoothClassResolver;
|
||||
@@ -55,6 +58,7 @@ public class BluetoothLeDevice implements Parcelable {
|
||||
private final long mFirstTimestamp;
|
||||
private int mCurrentRssi;
|
||||
private long mCurrentTimestamp;
|
||||
private transient Set<BluetoothService> mServiceSet;
|
||||
|
||||
/**
|
||||
* Instantiates a new Bluetooth LE device.
|
||||
@@ -221,6 +225,25 @@ public class BluetoothLeDevice implements Parcelable {
|
||||
return BluetoothClassResolver.resolveMajorDeviceClass(mDevice.getBluetoothClass().getMajorDeviceClass());
|
||||
}
|
||||
|
||||
public Set<BluetoothService> getBluetoothDeviceKnownSupportedServices() {
|
||||
if (mServiceSet == null) {
|
||||
synchronized (this) {
|
||||
if (mServiceSet == null) {
|
||||
final Set<BluetoothService> serviceSet = new HashSet<>();
|
||||
for (final BluetoothService service : BluetoothService.values()) {
|
||||
|
||||
if (mDevice.getBluetoothClass().hasService(service.getAndroidConstant())) {
|
||||
serviceSet.add(service);
|
||||
}
|
||||
}
|
||||
mServiceSet = Collections.unmodifiableSet(serviceSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mServiceSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the device.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package uk.co.alt236.bluetoothlelib.device;
|
||||
|
||||
import android.bluetooth.BluetoothClass;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public enum BluetoothService {
|
||||
AUDIO(BluetoothClass.Service.AUDIO),
|
||||
CAPTURE(BluetoothClass.Service.CAPTURE),
|
||||
INFORMATION(BluetoothClass.Service.INFORMATION),
|
||||
LIMITED_DISCOVERABILITY(BluetoothClass.Service.LIMITED_DISCOVERABILITY),
|
||||
NETWORKING(BluetoothClass.Service.NETWORKING),
|
||||
OBJECT_TRANSFER(BluetoothClass.Service.OBJECT_TRANSFER),
|
||||
POSITIONING(BluetoothClass.Service.POSITIONING),
|
||||
RENDER(BluetoothClass.Service.RENDER),
|
||||
TELEPHONY(BluetoothClass.Service.TELEPHONY);
|
||||
|
||||
private final int mAndroidConstant;
|
||||
|
||||
BluetoothService(final int androidCode){
|
||||
mAndroidConstant = androidCode;
|
||||
}
|
||||
|
||||
public int getAndroidConstant(){
|
||||
return mAndroidConstant;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import java.util.Locale;
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import uk.co.alt236.bluetoothlelib.device.BluetoothLeDevice;
|
||||
import uk.co.alt236.bluetoothlelib.device.BluetoothService;
|
||||
import uk.co.alt236.bluetoothlelib.device.adrecord.AdRecord;
|
||||
import uk.co.alt236.bluetoothlelib.device.mfdata.IBeaconManufacturerData;
|
||||
import uk.co.alt236.bluetoothlelib.resolvers.CompanyIdentifierResolver;
|
||||
@@ -56,6 +57,7 @@ public class DeviceDetailsActivity extends AppCompatActivity {
|
||||
final TextView tvAddress = (TextView) lt.findViewById(R.id.deviceAddress);
|
||||
final TextView tvClass = (TextView) lt.findViewById(R.id.deviceClass);
|
||||
final TextView tvMajorClass = (TextView) lt.findViewById(R.id.deviceMajorClass);
|
||||
final TextView tvServices = (TextView) lt.findViewById(R.id.deviceServiceList);
|
||||
final TextView tvBondingState = (TextView) lt.findViewById(R.id.deviceBondingState);
|
||||
|
||||
tvName.setText(device.getName());
|
||||
@@ -64,6 +66,24 @@ public class DeviceDetailsActivity extends AppCompatActivity {
|
||||
tvMajorClass.setText(device.getBluetoothDeviceMajorClassName());
|
||||
tvBondingState.setText(device.getBluetoothDeviceBondState());
|
||||
|
||||
final String supportedServices;
|
||||
if(device.getBluetoothDeviceKnownSupportedServices().isEmpty()){
|
||||
supportedServices = getString(R.string.no_known_services);
|
||||
} else {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(final BluetoothService service : device.getBluetoothDeviceKnownSupportedServices()){
|
||||
if(sb.length() > 0){
|
||||
sb.append(", ");
|
||||
}
|
||||
|
||||
sb.append(service);
|
||||
}
|
||||
supportedServices = sb.toString();
|
||||
}
|
||||
|
||||
tvServices.setText(supportedServices);
|
||||
|
||||
adapter.addView(lt);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,16 @@
|
||||
android:id="@+id/deviceMajorClass"
|
||||
style="@style/GridLayoutDataTextView"/>
|
||||
|
||||
<TextView
|
||||
style="@style/GridLayoutTitleTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/label_device_services"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/deviceServiceList"
|
||||
style="@style/GridLayoutDataTextView"/>
|
||||
|
||||
<TextView
|
||||
style="@style/GridLayoutTitleTextView"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<string name="unknown_characteristic">Unknown characteristic</string>
|
||||
<string name="unknown_device">Unknown device</string>
|
||||
<string name="unknown_service">Unknown service</string>
|
||||
<string name="no_known_services">No known services</string>
|
||||
|
||||
<!-- Formatters -->
|
||||
<string name="formatter_meters">%sm</string>
|
||||
@@ -54,6 +55,7 @@
|
||||
<string name="label_device_address">Device address:</string>
|
||||
<string name="label_device_class">Device Class:</string>
|
||||
<string name="label_device_major_class">Major Class:</string>
|
||||
<string name="label_device_services">Services:</string>
|
||||
<string name="label_device_name">Device Name:</string>
|
||||
<string name="label_distance">Distance:</string>
|
||||
<string name="label_first_rssi">First RSSI:</string>
|
||||
|
||||
Reference in New Issue
Block a user