Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLE callback on init #5

Open
daimonkor opened this issue Feb 3, 2016 · 0 comments
Open

BLE callback on init #5

daimonkor opened this issue Feb 3, 2016 · 0 comments

Comments

@daimonkor
Copy link
Contributor

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");
        }
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant