Android Open Source - BLE-MIDI-for-Android Midi Output Device

From Project

Back to project page BLE-MIDI-for-Android.


The source code is released under:

Apache License

If you think the Android project BLE-MIDI-for-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package jp.kshoji.blemidi.peripheral;
/*from w w w.j  av a 2s. c om*/
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattServer;
import android.text.TextUtils;

 * MidiOutputDevice for Peripheral
 * @author K.Shoji
public class MidiOutputDevice extends jp.kshoji.blemidi.device.MidiOutputDevice {
    private final BluetoothGattServer bluetoothGattServer;
    private final BluetoothDevice bluetoothDevice;

     * Constructor for Peripheral
     * @param bluetoothDevice the device
     * @param bluetoothGattServer the gatt server
     * @param midiCharacteristic the characteristic of device
    public MidiOutputDevice(final BluetoothDevice bluetoothDevice, final BluetoothGattServer bluetoothGattServer, final BluetoothGattCharacteristic midiCharacteristic) {
        this.bluetoothDevice = bluetoothDevice;
        this.bluetoothGattServer = bluetoothGattServer;

        this.midiOutputCharacteristic = midiCharacteristic;

    public String getDeviceName() {
        if (TextUtils.isEmpty(bluetoothDevice.getName())) {
            return bluetoothDevice.getAddress();
        return bluetoothDevice.getName();

    public void transferData(byte[] writeBuffer) {

        try {
            bluetoothGattServer.notifyCharacteristicChanged(bluetoothDevice, midiOutputCharacteristic, false);
        } catch (Throwable ignored) {
            // ignore it

Java Source Code List