当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothAdapter.isMultipleAdvertisementSupported方法代码示例

本文整理汇总了Java中android.bluetooth.BluetoothAdapter.isMultipleAdvertisementSupported方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.isMultipleAdvertisementSupported方法的具体用法?Java BluetoothAdapter.isMultipleAdvertisementSupported怎么用?Java BluetoothAdapter.isMultipleAdvertisementSupported使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.bluetooth.BluetoothAdapter的用法示例。


在下文中一共展示了BluetoothAdapter.isMultipleAdvertisementSupported方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkBluetooth

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
static public boolean checkBluetooth(Context context){
    BluetoothManager bm = (BluetoothManager) context.getSystemService(BLUETOOTH_SERVICE);
    BluetoothAdapter ba = bm.getAdapter();
    if (ba == null) {
        //Bluetooth is disabled
        Log.e(TAG, "BluetoothAdapter not available!");
        return false;
    }

    if(!ba.isEnabled()) {
        Log.w(TAG, "BluetoothAdapter not enabled!");
        ba.enable();
    }

    if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Log.e(TAG, "Bluetooth LE is not supported");
        return false;
    }

    if(!ba.isMultipleAdvertisementSupported()){
        Log.i(TAG, "No Multiple Advertisement Support!");
    }

    return ba.isEnabled();
}
 
开发者ID:holgi-s,项目名称:RangeThings,代码行数:26,代码来源:GattServer.java

示例2: isSupported

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static boolean isSupported(Context context) {
    PackageManager packageManager = context.getPackageManager();
    if (!packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) || !packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
        return false;

    BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
    return bluetoothAdapter != null && getBluetoothAdapterAddress(bluetoothAdapter) != null && bluetoothAdapter.isMultipleAdvertisementSupported();
}
 
开发者ID:aarmea,项目名称:noise,代码行数:10,代码来源:BluetoothSyncService.java

示例3: isBlePeripheralSupported

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
 * Check if Bluetooth LE Peripheral mode supported on the running environment.
 *
 * @param context the context
 * @return true if supported
 */
@SuppressLint("NewApi")
public static boolean isBlePeripheralSupported(@NonNull final Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return false;
    }

    final BluetoothAdapter bluetoothAdapter =  ((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();

    if (bluetoothAdapter == null) {
        return false;
    }

    return bluetoothAdapter.isMultipleAdvertisementSupported();
}
 
开发者ID:kshoji,项目名称:BLE-HID-Peripheral-for-Android,代码行数:21,代码来源:BleUtils.java

示例4: HidPeripheral

import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
 * Constructor<br />
 * Before constructing the instance, check the Bluetooth availability.
 *
 * @param context the ApplicationContext
 * @param needInputReport true: serves 'Input Report' BLE characteristic
 * @param needOutputReport true: serves 'Output Report' BLE characteristic
 * @param needFeatureReport true: serves 'Feature Report' BLE characteristic
 * @param dataSendingRate sending rate in milliseconds
 * @throws UnsupportedOperationException if starting Bluetooth LE Peripheral failed
 */
protected HidPeripheral(final Context context, final boolean needInputReport, final boolean needOutputReport, final boolean needFeatureReport, final int dataSendingRate) throws UnsupportedOperationException {
    applicationContext = context.getApplicationContext();
    handler = new Handler(applicationContext.getMainLooper());

    final BluetoothManager bluetoothManager = (BluetoothManager) applicationContext.getSystemService(Context.BLUETOOTH_SERVICE);

    final BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
    if (bluetoothAdapter == null) {
        throw new UnsupportedOperationException("Bluetooth is not available.");
    }

    if (!bluetoothAdapter.isEnabled()) {
        throw new UnsupportedOperationException("Bluetooth is disabled.");
    }

    Log.d(TAG, "isMultipleAdvertisementSupported:" + bluetoothAdapter.isMultipleAdvertisementSupported());
    if (!bluetoothAdapter.isMultipleAdvertisementSupported()) {
        throw new UnsupportedOperationException("Bluetooth LE Advertising not supported on this device.");
    }

    bluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    Log.d(TAG, "bluetoothLeAdvertiser: " + bluetoothLeAdvertiser);
    if (bluetoothLeAdvertiser == null) {
        throw new UnsupportedOperationException("Bluetooth LE Advertising not supported on this device.");
    }

    gattServer = bluetoothManager.openGattServer(applicationContext, gattServerCallback);
    if (gattServer == null) {
        throw new UnsupportedOperationException("gattServer is null, check Bluetooth is ON.");
    }

    // setup services
    addService(setUpHidService(needInputReport, needOutputReport, needFeatureReport));
    addService(setUpDeviceInformationService());
    addService(setUpBatteryService());
    
    // send report each dataSendingRate, if data available
    new Timer().scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            final byte[] polled = inputReportQueue.poll();
            if (polled != null && inputReportCharacteristic != null) {
                inputReportCharacteristic.setValue(polled);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        final Set<BluetoothDevice> devices = getDevices();
                        for (final BluetoothDevice device : devices) {
                            try {
                                if (gattServer != null) {
                                    gattServer.notifyCharacteristicChanged(device, inputReportCharacteristic, false);
                                }
                            } catch (final Throwable ignored) {

                            }
                        }
                    }
                });
            }
        }
    }, 0, dataSendingRate);
}
 
开发者ID:kshoji,项目名称:BLE-HID-Peripheral-for-Android,代码行数:74,代码来源:HidPeripheral.java


注:本文中的android.bluetooth.BluetoothAdapter.isMultipleAdvertisementSupported方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。