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


Java RxBleClient类代码示例

本文整理汇总了Java中com.polidea.rxandroidble.RxBleClient的典型用法代码示例。如果您正苦于以下问题:Java RxBleClient类的具体用法?Java RxBleClient怎么用?Java RxBleClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: onCreate

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        UserError.Log.wtf(TAG, "Not high enough Android version to run: " + Build.VERSION.SDK_INT);
    } else {

        registerReceiver(mBondStateReceiver, new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED));

        final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
        pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
        registerReceiver(mPairingRequestRecevier, pairingRequestFilter);

        checkAlwaysScanModels();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            android_wear = (getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_WATCH;
            if (android_wear) {
                UserError.Log.d(TAG,"We are running on Android Wear");
            }
        }
    }
    if (d) RxBleClient.setLogLevel(RxBleLog.DEBUG);
}
 
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:26,代码来源:Ob1G5CollectionService.java

示例2: initialize

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
public static void initialize(@NonNull Context context) {
    Log.v(TAG, "Initializing with context: " + context);
    BluetoothClient instance = getInstance();
    instance.rxBleClient = RxBleClient.create(context);
    BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
    instance.bluetoothAdapter = bluetoothManager.getAdapter();
    if (instance.bluetoothAdapter == null) {
        Log.e(TAG, "Bluetooth adapter is not available");
    }
}
 
开发者ID:neXenio,项目名称:BLE-Indoor-Positioning,代码行数:11,代码来源:BluetoothClient.java

示例3: checkAdapterAndServicesState

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
@NonNull
private static Observable<RxBleClient.State> checkAdapterAndServicesState(
        Boolean permissionWasInitiallyGranted,
        RxBleAdapterWrapper rxBleAdapterWrapper,
        Observable<RxBleAdapterStateObservable.BleAdapterState> rxBleAdapterStateObservable,
        final Observable<Boolean> locationServicesOkObservable
) {
    final Observable<RxBleClient.State> stateObservable = rxBleAdapterStateObservable
            .startWith(rxBleAdapterWrapper.isBluetoothEnabled()
                    ? RxBleAdapterStateObservable.BleAdapterState.STATE_ON
                    /*
                    Actual RxBleAdapterStateObservable.BleAdapterState does not really matter - because in the .switchMap() below
                    we only check if it is STATE_ON or not
                     */
                    : RxBleAdapterStateObservable.BleAdapterState.STATE_OFF)
            .switchMap(new Func1<RxBleAdapterStateObservable.BleAdapterState, Observable<RxBleClient.State>>() {
                @Override
                public Observable<RxBleClient.State> call(
                        RxBleAdapterStateObservable.BleAdapterState bleAdapterState) {
                    if (bleAdapterState != RxBleAdapterStateObservable.BleAdapterState.STATE_ON) {
                        return Observable.just(RxBleClient.State.BLUETOOTH_NOT_ENABLED);
                    } else {
                        return locationServicesOkObservable.map(new Func1<Boolean, RxBleClient.State>() {
                            @Override
                            public RxBleClient.State call(Boolean locationServicesOk) {
                                return locationServicesOk ? RxBleClient.State.READY
                                        : RxBleClient.State.LOCATION_SERVICES_NOT_ENABLED;
                            }
                        });
                    }
                }
            });
    return permissionWasInitiallyGranted
            /*
            If permission was granted from the beginning then the first value is not a change as the above Observable does emit value
            at the moment of Subscription.
             */
            ? stateObservable.skip(1)
            : stateObservable;
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:41,代码来源:ClientStateObservable.java

示例4: initialize

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
private synchronized void initialize() {
    if (state == STATE.INIT) {
        msg("Initializing");
        static_connection_state = null;
        if (rxBleClient == null) {
            rxBleClient = RxBleClient.create(xdrip.getAppContext());
        }
        init_tx_id();
        // load prefs etc
        changeState(STATE.SCAN);
    } else {
        UserError.Log.wtf(TAG, "Attempt to initialize when not in INIT state");
    }
}
 
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:15,代码来源:Ob1G5CollectionService.java

示例5: getRxBleClient

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
public static RxBleClient getRxBleClient(Context context) {
    AppExt app = (AppExt) context.getApplicationContext();
    return app.mRxBleClient;
}
 
开发者ID:KunYi,项目名称:SensorTag2Testing,代码行数:5,代码来源:AppExt.java

示例6: onCreate

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    mRxBleClient = RxBleClient.create(this);
    RxBleClient.setLogLevel(RxBleLog.DEBUG);
}
 
开发者ID:KunYi,项目名称:SensorTag2Testing,代码行数:7,代码来源:AppExt.java

示例7: ClientStateObservable

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
@Inject
protected ClientStateObservable(
        final RxBleAdapterWrapper rxBleAdapterWrapper,
        final Observable<RxBleAdapterStateObservable.BleAdapterState> bleAdapterStateObservable,
        @Named(ClientComponent.NamedBooleanObservables.LOCATION_SERVICES_OK) final Observable<Boolean> locationServicesOkObservable,
        final LocationServicesStatus locationServicesStatus,
        @Named(ClientComponent.NamedSchedulers.TIMEOUT) final Scheduler timerScheduler
) {
    super(new OnSubscribeCreate<>(
            new Action1<Emitter<RxBleClient.State>>() {
                @Override
                public void call(Emitter<RxBleClient.State> emitter) {
                    if (!rxBleAdapterWrapper.hasBluetoothAdapter()) {
                        emitter.onCompleted();
                        return;
                    }

                    final Subscription changingStateSubscription = checkPermissionUntilGranted(locationServicesStatus, timerScheduler)
                            .flatMapObservable(new Func1<Boolean, Observable<RxBleClient.State>>() {
                                @Override
                                public Observable<RxBleClient.State> call(Boolean permissionWasInitiallyGranted) {
                                    return checkAdapterAndServicesState(
                                            permissionWasInitiallyGranted,
                                            rxBleAdapterWrapper,
                                            bleAdapterStateObservable,
                                            locationServicesOkObservable
                                    );
                                }
                            })
                            .distinctUntilChanged()
                            .subscribe(emitter);

                    emitter.setCancellation(new Cancellable() {
                        @Override
                        public void cancel() throws Exception {
                            changingStateSubscription.unsubscribe();
                        }
                    });
                }
            },
            Emitter.BackpressureMode.LATEST
    ));
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:44,代码来源:ClientStateObservable.java

示例8: getRxBleClient

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
/**
 * In practise you will use some kind of dependency injection pattern.
 */
public static RxBleClient getRxBleClient(Context context) {
    SampleApplication application = (SampleApplication) context.getApplicationContext();
    return application.rxBleClient;
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:8,代码来源:SampleApplication.java

示例9: onCreate

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    rxBleClient = RxBleClient.create(this);
    RxBleClient.setLogLevel(RxBleLog.VERBOSE);
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:7,代码来源:SampleApplication.java

示例10: onCreate

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final RxBleClient rxBleClient = SampleApplication.getRxBleClient(this);

    subscription = rxBleClient.getBleDevice(DUMMY_DEVICE_ADDRESS) // get our assumed device
            .establishConnection(false) // establish the connection
            .flatMap(rxBleConnection -> Observable.combineLatest(
                    // after establishing the connection lets setup the notifications
                    rxBleConnection.setupNotification(DEVICE_CALLBACK_0),
                    rxBleConnection.setupNotification(DEVICE_CALLBACK_1),
                    Pair::new
            ), (rxBleConnection, callbackObservablePair) -> { // after the setup lets start the long write
                Observable<byte[]> deviceCallback0 = callbackObservablePair.first;
                Observable<byte[]> deviceCallback1 = callbackObservablePair.second;
                return rxBleConnection.createNewLongWriteBuilder() // create a new long write builder
                        .setBytes(bytesToWrite) // REQUIRED - set the bytes to write
                        /**
                         * REQUIRED - To perform a write you need to specify to which characteristic you want to write. You can do it
                         * either by calling {@link LongWriteOperationBuilder#setCharacteristicUuid(UUID)} or
                         * {@link LongWriteOperationBuilder#setCharacteristic(BluetoothGattCharacteristic)}
                         */
                        .setCharacteristicUuid(WRITE_CHARACTERISTIC) // set the UUID of the characteristic to write
                        // .setCharacteristic( /* some BluetoothGattCharacteristic */ ) // alternative to setCharacteristicUuid()
                        /**
                         * If you want to send batches with length other than default.
                         * Default value is 20 bytes if MTU was not negotiated. If the MTU was negotiated prior to the Long Write
                         * Operation execution then the batch size default is the new MTU.
                         */
                        // .setMaxBatchSize( /* your batch size */ )
                        /**
                         * Inform the Long Write when we want to send the next batch of data. If not set the operation will try to write
                         * the next batch of data as soon as the Android will call `BluetoothGattCallback.onCharacteristicWrite()` but
                         * we want to postpone it until also DC0 and DC1 will emit.
                         */
                        .setWriteOperationAckStrategy(new RxBleConnection.WriteOperationAckStrategy() {
                            @Override
                            public Observable<Boolean> call(Observable<Boolean> booleanObservable) {
                                return Observable.zip(
                                        // so we zip three observables
                                        deviceCallback0, // DEVICE_CALLBACK_0
                                        deviceCallback1, // DEVICE_CALLBACK_1
                                        booleanObservable, /* previous batch of data was sent - we do not care if value emitted from
                                        the booleanObservable is TRUE or FALSE. But the value will be TRUE unless the previously sent
                                        data batch was the final one */
                                        (callback0, callback1, aBoolean) -> aBoolean // value of the returned Boolean is not important
                                );
                            }
                        })
                        .build();
            })
            .flatMap(observable -> observable)
            .take(1) // after the successful write we are no longer interested in the connection so it will be released
            .subscribe(
                    bytes -> {
                        // react
                    },
                    throwable -> {
                        // handle error
                    }
            );
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:64,代码来源:LongWriteExampleActivity.java

示例11: ArduinoManager

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
public ArduinoManager(Context context, RxBleClient rxBleClient) {
    this.rxBleClient = rxBleClient;
    this.context = context;
}
 
开发者ID:elloza,项目名称:ArduinoBLEAndroid,代码行数:5,代码来源:ArduinoManager.java

示例12: provideBleClient

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
@Provides
RxBleClient provideBleClient(Context context) {
    return RxBleClient.create(context);
}
 
开发者ID:elloza,项目名称:ArduinoBLEAndroid,代码行数:5,代码来源:BLEModule.java

示例13: provideArduinoManager

import com.polidea.rxandroidble.RxBleClient; //导入依赖的package包/类
@Provides
ArduinoManager provideArduinoManager(Context context, RxBleClient rxClient) {

    return new ArduinoManager(context, rxClient);
}
 
开发者ID:elloza,项目名称:ArduinoBLEAndroid,代码行数:6,代码来源:BLEModule.java


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