下面列出了android.bluetooth.BluetoothAdapter#isMultipleAdvertisementSupported ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* コンストラクタ.
* @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.");
}
}
private void onBluetoothStateChanged(Context context) {
// Setup advertiser
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
if (!adapter.isEnabled()) {
Log.w(TAG, "BluetoothLE is disabled");
}
if (!adapter.isMultipleAdvertisementSupported()) {
Log.w(TAG, "Multiple advertisement not supported");
}
mAdvertiser = adapter.getBluetoothLeAdvertiser();
if (mAdvertiser == null) {
Log.w(TAG, "Device does not support Peripheral Mode");
}
} else {
Log.w(TAG, "Device does not support Bluetooth");
}
if (mAdvertiser == null) {
mIsAdvertising = false;
}
if (mShouldStartAdvertising && mAdvertiser != null) {
startAdvertising(context);
}
}
/**
* 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();
}
public static boolean isAdvertisingSupportedByChipset(BluetoothAdapter adapter) {
return adapter.isMultipleAdvertisementSupported();
}
public static boolean isAdvertisingSupportedByChipset(BluetoothAdapter adapter) {
return adapter.isMultipleAdvertisementSupported();
}