@Override
    @SuppressLint("MissingPermission") // We check before this is called
    public boolean onOptionsItemSelected(final MenuItem item) {
        final int itemId = item.getItemId();
        if (itemId == R.id.menu_connect) {
            mBluetoothLeService.connect(mDevice.getAddress());
            return true;
        } else if (itemId == R.id.menu_disconnect) {
            mBluetoothLeService.disconnect();
            return true;
        } else if (itemId == android.R.id.home) {
            onBackPressed();
            return true;
        } else if (itemId == R.id.menu_share) {
            final Intent intent = new Intent(Intent.ACTION_SEND);
            final String subject = getString(
                    R.string.exporter_email_device_services_subject,
                    mDevice.getName(),
                    mDevice.getAddress());

            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_SUBJECT, subject);
            intent.putExtra(Intent.EXTRA_TEXT, mExportString);

            startActivity(Intent.createChooser(
                    intent,
                    getString(R.string.exporter_email_device_list_picker_text)));

            return true;
        }
        return super.onOptionsItemSelected(item);
    }
For a given BLE device, this Activity provides the user interface to connect, display data,
and display GATT services and characteristics supported by the device.  The Activity
communicates with {@code BluetoothLeService}, which in turn interacts with the
Bluetooth LE API.
sample_app/src/main/java/uk/co/alt236/btlescan/ui/control/DeviceControlActivity.java