if (!((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().isMultipleAdvertisementSupported()) { returnCode = NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS;
@Test @Config(minSdk = LOLLIPOP) public void canGetAndSetMultipleAdvertisementSupport() throws Exception { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); // By default, multiple advertising is supported. assertThat(adapter.isMultipleAdvertisementSupported()).isTrue(); // Flipping it off should update state accordingly. shadowOf(adapter).setIsMultipleAdvertisementSupported(false); assertThat(adapter.isMultipleAdvertisementSupported()).isFalse(); }
public boolean supportPeripheralMode() { return mBtAdapter.isMultipleAdvertisementSupported(); } }
/** * Checks whether BLE advertising is supported. This method must only be called after checking * that Bluetooth is enabled. * @return True if a BLE advertiser instance already exists or BLE advertisement is supported. */ public boolean canAdvertise() { if (null != mBleAdvertiser) return true; if (!mBluetoothAdapter.isMultipleAdvertisementSupported()) { return false; } mBleAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser(); return null != mBleAdvertiser; }
BluetoothManager btManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE); BluetoothAdapter btAdapter = btManager.getAdapter(); if (btAdapter.isEnabled()) boolean isSupported = btAdapter.isMultipleAdvertisementSupported()) ;
/** * BLEペリフェラルがサポートされているか確認を行います. * * @param context このアプリケーションが属するコンテキスト * @return サポートされている場合はtrue、それ以外はfalse */ @SuppressLint("NewApi") public static boolean isBlePeripheralSupported(@NonNull final Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return false; } BluetoothAdapter bluetoothAdapter = getAdapter(context); return bluetoothAdapter != null && bluetoothAdapter.isMultipleAdvertisementSupported(); }
/** * 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(); }
/** * コンストラクタ. * @param context このインスタンスが属するコンテキスト * @throws UnsupportedOperationException BluetoothやBLEがサポートされていない場合に発生 */ AbstractHOGPServer(final Context context) throws UnsupportedOperationException { mApplicationContext = context.getApplicationContext(); final BluetoothManager btMgr = (BluetoothManager) mApplicationContext.getSystemService(Context.BLUETOOTH_SERVICE); final BluetoothAdapter btAdapter = btMgr.getAdapter(); if (btAdapter == null) { throw new UnsupportedOperationException("Bluetooth is not available."); } if (!btAdapter.isEnabled()) { throw new UnsupportedOperationException("Bluetooth is disabled."); } if (!btAdapter.isMultipleAdvertisementSupported()) { throw new UnsupportedOperationException("Bluetooth LE Advertising not supported on this device."); } mBluetoothLeAdvertiser = btAdapter.getBluetoothLeAdvertiser(); if (mBluetoothLeAdvertiser == null) { throw new UnsupportedOperationException("Bluetooth LE Advertising not supported on this device."); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mText = (TextView) findViewById( R.id.text ); mDiscoverButton = (Button) findViewById( R.id.discover_btn ); mAdvertiseButton = (Button) findViewById( R.id.advertise_btn ); mDiscoverButton.setOnClickListener( this ); mAdvertiseButton.setOnClickListener( this ); mBluetoothLeScanner = BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner(); if( !BluetoothAdapter.getDefaultAdapter().isMultipleAdvertisementSupported() ) { Toast.makeText( this, "Multiple advertisement not supported", Toast.LENGTH_SHORT ).show(); mAdvertiseButton.setEnabled( false ); mDiscoverButton.setEnabled( false ); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case Constants.REQUEST_ENABLE_BT: if (resultCode == RESULT_OK) { // Bluetooth is now Enabled, are Bluetooth Advertisements supported on // this device? if (mBluetoothAdapter.isMultipleAdvertisementSupported()) { // Everything is supported and enabled, load the fragments. setupFragments(); } else { // Bluetooth Advertisements are not supported. showErrorText(R.string.bt_ads_not_supported); } } else { // User declined to enable Bluetooth, exit the app. Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); finish(); } default: super.onActivityResult(requestCode, resultCode, data); } }
Log.d(TAG, "isMultipleAdvertisementSupported:" + bluetoothAdapter.isMultipleAdvertisementSupported()); if (!bluetoothAdapter.isMultipleAdvertisementSupported()) { throw new UnsupportedOperationException("Bluetooth LE Advertising not supported on this device.");
if (mBluetoothAdapter.isMultipleAdvertisementSupported()) {
if (!mBluetoothAdapter.isMultipleAdvertisementSupported()) { return false;
if(!mAdapter.isMultipleAdvertisementSupported()) return -3;