當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。