Skip to content

BLE callback on init #5

@daimonkor

Description

@daimonkor

Please add callback when BLEService was inited, thanks. Sorry, but I use fragment and main activity is owner BLE Service, so I needed callback on service connection at fragment

    private final ServiceConnection serviceConnectionListener = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName componentName, IBinder service) {
            LogManager.LogEA("Service connected");
            mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService();
            if (!mBluetoothLeService.initialize()) {
                LogManager.LogEA(getString(R.string.unable_to_initialize_bluetooth));
                MainActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this).setMessage(getString(R.string.unable_to_initialize_bluetooth)).setCancelable(false);
                        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                MainActivity.this.finish();
                            }
                        });
                        builder.create().show();
                    }
                });
            }else{
                bluetoothListener.onBluetoothServiceConnected();
                LogManager.LogEA(bluetoothListener.getBluetoothListenerId());
            }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            mBluetoothLeService = null;
            LogManager.LogEA("Service disconnected");
        }
    };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions