本文整理汇总了Java中android.bluetooth.BluetoothClass.getDeviceClass方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothClass.getDeviceClass方法的具体用法?Java BluetoothClass.getDeviceClass怎么用?Java BluetoothClass.getDeviceClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothClass
的用法示例。
在下文中一共展示了BluetoothClass.getDeviceClass方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isHealthWearable
import android.bluetooth.BluetoothClass; //导入方法依赖的package包/类
public boolean isHealthWearable(BluetoothDevice device) {
BluetoothClass bluetoothClass = device.getBluetoothClass();
if (bluetoothClass == null) {
LOG.warn("unable to determine bluetooth device class of " + device);
return false;
}
if (bluetoothClass.getMajorDeviceClass() == BluetoothClass.Device.Major.WEARABLE
|| bluetoothClass.getMajorDeviceClass() == BluetoothClass.Device.Major.UNCATEGORIZED) {
int deviceClasses =
BluetoothClass.Device.HEALTH_BLOOD_PRESSURE
| BluetoothClass.Device.HEALTH_DATA_DISPLAY
| BluetoothClass.Device.HEALTH_PULSE_RATE
| BluetoothClass.Device.HEALTH_WEIGHING
| BluetoothClass.Device.HEALTH_UNCATEGORIZED
| BluetoothClass.Device.HEALTH_PULSE_OXIMETER
| BluetoothClass.Device.HEALTH_GLUCOSE;
return (bluetoothClass.getDeviceClass() & deviceClasses) != 0;
}
return false;
}
示例2: getBluetoothDevices
import android.bluetooth.BluetoothClass; //导入方法依赖的package包/类
public static void getBluetoothDevices(){
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.enable();
btDeviceNames = new ArrayList<String>();
Set<BluetoothDevice> a= mBluetoothAdapter.getBondedDevices();
Iterator I=a.iterator();
BluetoothDevice n=null;
while(I.hasNext()) {
n = (BluetoothDevice) I.next();
BluetoothClass x=n.getBluetoothClass();
if(x!=null){
int xc=x.getDeviceClass();
if((xc==BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO)||
(xc==BluetoothClass.Device.AUDIO_VIDEO_PORTABLE_AUDIO)||
(xc==BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET)||
(xc==BluetoothClass.Device.AUDIO_VIDEO_LOUDSPEAKER))
{
String k = n.getName();
btDeviceNames.add(k);
}
}
}
}
示例3: canBluetooth
import android.bluetooth.BluetoothClass; //导入方法依赖的package包/类
public boolean canBluetooth() {
// Detect if any bluetooth a device is available for call
if (bluetoothAdapter == null) {
// Device does not support Bluetooth
return false;
}
boolean hasConnectedDevice = false;
//If bluetooth is on
if(bluetoothAdapter.isEnabled()) {
//We get all bounded bluetooth devices
// bounded is not enough, should search for connected devices....
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
for(BluetoothDevice device : pairedDevices) {
BluetoothClass bluetoothClass = device.getBluetoothClass();
if (bluetoothClass != null) {
int deviceClass = bluetoothClass.getDeviceClass();
if(bluetoothClass.hasService(Service.RENDER) ||
deviceClass == Device.AUDIO_VIDEO_WEARABLE_HEADSET ||
deviceClass == Device.AUDIO_VIDEO_CAR_AUDIO ||
deviceClass == Device.AUDIO_VIDEO_HANDSFREE ) {
//And if any can be used as a audio handset
hasConnectedDevice = true;
break;
}
}
}
}
boolean retVal = hasConnectedDevice && audioManager.isBluetoothScoAvailableOffCall();
Log.d(THIS_FILE, "Can I do BT ? "+retVal);
return retVal;
}
示例4: BluetoothDeviceInfo
import android.bluetooth.BluetoothClass; //导入方法依赖的package包/类
BluetoothDeviceInfo(final BluetoothDevice device) {
name = device.getName();
address = device.getAddress();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
type = device.getType();
} else {
type = 0;
}
final BluetoothClass clazz = device.getBluetoothClass();
deviceClass = clazz != null ? clazz.getDeviceClass() : 0;
bondState = device.getBondState();
}
示例5: canBluetooth
import android.bluetooth.BluetoothClass; //导入方法依赖的package包/类
public boolean canBluetooth() {
// Detect if any bluetooth a device is available for call
if (bluetoothAdapter == null) {
// Device does not support Bluetooth
return false;
}
boolean hasConnectedDevice = false;
//If bluetooth is on
if (bluetoothAdapter.isEnabled()) {
//We get all bounded bluetooth devices
// bounded is not enough, should search for connected devices....
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
for (BluetoothDevice device : pairedDevices) {
BluetoothClass bluetoothClass = device.getBluetoothClass();
if (bluetoothClass != null) {
int deviceClass = bluetoothClass.getDeviceClass();
if (bluetoothClass.hasService(BluetoothClass.Service.RENDER) ||
deviceClass == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET ||
deviceClass == BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO ||
deviceClass == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) {
//And if any can be used as a audio handset
hasConnectedDevice = true;
break;
}
}
}
}
boolean retVal = hasConnectedDevice && audioManager.isBluetoothScoAvailableOffCall();
Log.d(TAG, "Can I do BT ? " + retVal);
return retVal;
}
示例6: isAvailable
import android.bluetooth.BluetoothClass; //导入方法依赖的package包/类
public static boolean isAvailable() {
if (!ba.isEnabled())
return false;
Set<BluetoothDevice> devs = ba.getBondedDevices();
for (final BluetoothDevice dev : devs) {
BluetoothClass cl = dev.getBluetoothClass();
if (cl != null && (cl.hasService(Service.RENDER) ||
cl.getDeviceClass() == Device.AUDIO_VIDEO_HANDSFREE ||
cl.getDeviceClass() == Device.AUDIO_VIDEO_CAR_AUDIO ||
cl.getDeviceClass() == Device.AUDIO_VIDEO_WEARABLE_HEADSET))
return true;
}
return false;
}
示例7: existBluetoothHeadset
import android.bluetooth.BluetoothClass; //导入方法依赖的package包/类
private boolean existBluetoothHeadset() {
for (BluetoothDevice dispositivo: bluetoothAdapter.getBondedDevices()) {
BluetoothClass clase= dispositivo.getBluetoothClass();
switch (clase.getDeviceClass()) {
case BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES:
return true;
case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
return true;
case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
return true;
}
}
return false;
}
示例8: onReceive
import android.bluetooth.BluetoothClass; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent)
{
Message msg = Message.obtain();
String action = intent.getAction();
if(BluetoothDevice.ACTION_FOUND.equals(action))
{
bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
BluetoothClass blclass = intent.getParcelableExtra(BluetoothDevice.EXTRA_CLASS);
int Majorclass = blclass.getMajorDeviceClass();
int minorclass = blclass.getDeviceClass();
devicelist = new KrollDict();
try
{
devicelist.put("name",bluetoothDevice.getName());
devicelist.put("macaddress",bluetoothDevice.getAddress());
devicelist.put("pairedstatus",bluetoothDevice.getBondState());
}
catch (Exception e)
{
Log.w(TAG, "devicesFound exception: "+e.getMessage());
postError(e.getMessage());
}
devicesFound();
}
}
示例9: onReceive
import android.bluetooth.BluetoothClass; //导入方法依赖的package包/类
@SuppressWarnings({"deprecation", "synthetic-access"})
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) {
BluetoothDevice mConnectedHeadset = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
BluetoothClass bluetoothClass = mConnectedHeadset.getBluetoothClass();
if (bluetoothClass != null) {
// Check if device is a headset. Besides the 2 below, are there other
// device classes also qualified as headset?
int deviceClass = bluetoothClass.getDeviceClass();
if (deviceClass == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE
|| deviceClass == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET) {
// start bluetooth Sco audio connection.
// Calling startBluetoothSco() always returns faIL here,
// that why a count down timer is implemented to call
// startBluetoothSco() in the onTick.
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mIsCountDownOn = true;
mCountDown.start();
// override this if you want to do other thing when the device is connected.
onHeadsetConnected();
}
}
Log.d(TAG, mConnectedHeadset.getName() + " connected");
} else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
Log.d(TAG, "Headset disconnected");
if (mIsCountDownOn) {
mIsCountDownOn = false;
mCountDown.cancel();
}
mAudioManager.setMode(AudioManager.MODE_NORMAL);
// override this if you want to do other thing when the device is disconnected.
onHeadsetDisconnected();
} else if (action.equals(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED)) {
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE,
AudioManager.SCO_AUDIO_STATE_ERROR);
if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
mIsOnHeadsetSco = true;
if (mIsStarting) {
// When the device is connected before the application starts,
// ACTION_ACL_CONNECTED will not be received, so call onHeadsetConnected here
mIsStarting = false;
onHeadsetConnected();
}
if (mIsCountDownOn) {
mIsCountDownOn = false;
mCountDown.cancel();
}
// override this if you want to do other thing when Sco audio is connected.
onScoAudioConnected();
Log.d(TAG, "Sco connected");
} else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) {
Log.d(TAG, "Sco disconnected");
// Always receive SCO_AUDIO_STATE_DISCONNECTED on call to startBluetooth()
// which at that stage we do not want to do anything. Thus the if condition.
if (!mIsStarting) {
mIsOnHeadsetSco = false;
// Need to call stopBluetoothSco(), otherwise startBluetoothSco()
// will not be successful.
mAudioManager.stopBluetoothSco();
// override this if you want to do other thing when Sco audio is disconnected.
onScoAudioDisconnected();
}
}
}
}
示例10: isBluetoothDevicePs3
import android.bluetooth.BluetoothClass; //导入方法依赖的package包/类
/**
* Checks wether the specified device is a PS3 host. Weirdly enough, the PS3 reports
* a device class of 0x2c0108:
*
* Which means:
* - service (0x2c): Rendering | Capturing | Audio
* - major # (0x01): Computer
* - minor # (0x08): Server-class computer
*
* This setup seems rather generic for the ps3, however it will have to do for now.
* Another option, would be to check the bluetooth MAC prefix, which identifies the
* adapter vendor. CECHGxx units seems to be built with Alps Co. adapters (00:1B:FB)
* But to check it now could refrain this to work on other unchecked units.
*
* So, currently we will only check for service/major/minor.
*
* @param device
* @return
*/
public static boolean isBluetoothDevicePs3(BluetoothDevice device) {
if (device == null) {
return false;
}
BluetoothClass bluetoothClass = device.getBluetoothClass();
boolean isPs3 = PS3_MAJOR_MINOR == bluetoothClass.getDeviceClass();
int i = 0;
while (isPs3 && i < PS3_SVC_LIST.length) {
isPs3 = isPs3 && bluetoothClass.hasService(PS3_SVC_LIST[i]);
i++;
}
return isPs3;
}