FileDocCategorySizeDatePackage
BluetoothClass.javaAPI DocAndroid 5.1 API15634Thu Mar 12 22:22:10 GMT 2015android.bluetooth

BluetoothClass

public final class BluetoothClass extends Object implements android.os.Parcelable
Represents a Bluetooth class, which describes general characteristics and capabilities of a device. For example, a Bluetooth class will specify the general device type such as a phone, a computer, or headset, and whether it's capable of services such as audio or telephony.

Every Bluetooth class is composed of zero or more service classes, and exactly one device class. The device class is further broken down into major and minor device class components.

{@link BluetoothClass} is useful as a hint to roughly describe a device (for example to show an icon in the UI), but does not reliably describe which Bluetooth profiles or services are actually supported by a device. Accurate service discovery is done through SDP requests, which are automatically performed when creating an RFCOMM socket with {@link BluetoothDevice#createRfcommSocketToServiceRecord} and {@link BluetoothAdapter#listenUsingRfcommWithServiceRecord}

Use {@link BluetoothDevice#getBluetoothClass} to retrieve the class for a remote device.

Fields Summary
public static final int
ERROR
Legacy error value. Applications should use null instead.
private final int
mClass
public static final Parcelable.Creator
CREATOR
public static final int
PROFILE_HEADSET
public static final int
PROFILE_A2DP
public static final int
PROFILE_OPP
public static final int
PROFILE_HID
public static final int
PROFILE_PANU
public static final int
PROFILE_NAP
Constructors Summary
public BluetoothClass(int classInt)

hide


      
       
        mClass = classInt;
    
Methods Summary
public intdescribeContents()

        return 0;
    
public booleandoesClassMatch(int profile)
Check class bits for possible bluetooth profile support. This is a simple heuristic that tries to guess if a device with the given class bits might support specified profile. It is not accurate for all devices. It tries to err on the side of false positives.

param
profile The profile to be checked
return
True if this device might support specified profile.
hide


                                                                        
        
        if (profile == PROFILE_A2DP) {
            if (hasService(Service.RENDER)) {
                return true;
            }
            // By the A2DP spec, sinks must indicate the RENDER service.
            // However we found some that do not (Chordette). So lets also
            // match on some other class bits.
            switch (getDeviceClass()) {
                case Device.AUDIO_VIDEO_HIFI_AUDIO:
                case Device.AUDIO_VIDEO_HEADPHONES:
                case Device.AUDIO_VIDEO_LOUDSPEAKER:
                case Device.AUDIO_VIDEO_CAR_AUDIO:
                    return true;
                default:
                    return false;
            }
        } else if (profile == PROFILE_HEADSET) {
            // The render service class is required by the spec for HFP, so is a
            // pretty good signal
            if (hasService(Service.RENDER)) {
                return true;
            }
            // Just in case they forgot the render service class
            switch (getDeviceClass()) {
                case Device.AUDIO_VIDEO_HANDSFREE:
                case Device.AUDIO_VIDEO_WEARABLE_HEADSET:
                case Device.AUDIO_VIDEO_CAR_AUDIO:
                    return true;
                default:
                    return false;
            }
        } else if (profile == PROFILE_OPP) {
            if (hasService(Service.OBJECT_TRANSFER)) {
                return true;
            }

            switch (getDeviceClass()) {
                case Device.COMPUTER_UNCATEGORIZED:
                case Device.COMPUTER_DESKTOP:
                case Device.COMPUTER_SERVER:
                case Device.COMPUTER_LAPTOP:
                case Device.COMPUTER_HANDHELD_PC_PDA:
                case Device.COMPUTER_PALM_SIZE_PC_PDA:
                case Device.COMPUTER_WEARABLE:
                case Device.PHONE_UNCATEGORIZED:
                case Device.PHONE_CELLULAR:
                case Device.PHONE_CORDLESS:
                case Device.PHONE_SMART:
                case Device.PHONE_MODEM_OR_GATEWAY:
                case Device.PHONE_ISDN:
                    return true;
                default:
                    return false;
            }
        } else if (profile == PROFILE_HID) {
            return (getDeviceClass() & Device.Major.PERIPHERAL) == Device.Major.PERIPHERAL;
        } else if (profile == PROFILE_PANU || profile == PROFILE_NAP){
            // No good way to distinguish between the two, based on class bits.
            if (hasService(Service.NETWORKING)) {
                return true;
            }
            return (getDeviceClass() & Device.Major.NETWORKING) == Device.Major.NETWORKING;
        } else {
            return false;
        }
    
public booleanequals(java.lang.Object o)

        if (o instanceof BluetoothClass) {
            return mClass == ((BluetoothClass)o).mClass;
        }
        return false;
    
public intgetDeviceClass()
Return the (major and minor) device class component of this {@link BluetoothClass}.

Values returned from this function can be compared with the public constants in {@link BluetoothClass.Device} to determine which device class is encoded in this Bluetooth class.

return
device class component

        return (mClass & Device.BITMASK);
    
public intgetMajorDeviceClass()
Return the major device class component of this {@link BluetoothClass}.

Values returned from this function can be compared with the public constants in {@link BluetoothClass.Device.Major} to determine which major class is encoded in this Bluetooth class.

return
major device class component

    

                                                  
       
        return (mClass & Device.Major.BITMASK);
    
public booleanhasService(int service)
Return true if the specified service class is supported by this {@link BluetoothClass}.

Valid service classes are the public constants in {@link BluetoothClass.Service}. For example, {@link BluetoothClass.Service#AUDIO}.

param
service valid service class
return
true if the service class is supported

    

                                                 
        
        return ((mClass & Service.BITMASK & service) != 0);
    
public inthashCode()

        return mClass;
    
public java.lang.StringtoString()

        return Integer.toHexString(mClass);
    
public voidwriteToParcel(android.os.Parcel out, int flags)


          
        out.writeInt(mClass);