SAP Accessory protocol: connecting Smartphone to Gear S2 and beacon simultaneously

SAP Accessory protocol: connecting Smartphone to Gear S2 and beacon simultaneously

BY 18 Jun 2016 Web Application Development

Hello,

I have Samsung Galaxy S4 mini, with Android version 4.4.

I can connect without problems this Android phone to a beacon, and receive beacon events. It works.

I can connect without problems the Samsung Gear S2 to Smartphone and send/receive events, using SAP Accesory Protocol (SAP). It works.

In both cases, the communication works good separately.

When I establish simultaneous communications (smartphone-beacon and smartphone-gear s2 at same time), it works during a few seconds, and then I receive lost connection between smartphone and smartwatch.  I receive on Smartwatch Consumer Service error 513 (CONNECTION PEER DISCONNECTED).

Then, it is possible establish simultaneous connections using protocol bluetooth low energy? Is possible to connect Smartphone and Gear S2 through transport protocol TRANSPORT_WIFI? Do you have any sample working with TRANSPORT_WIFI? (If simultaneous connections are not possible, i can use wifi, but I don’t need wifi from smartwatch, i need wifi to send messages from smartphone to smartwatch).

Thank you,

Joaquim Puyo

 

public class ServiceConnection extends SASocket {
    public ServiceConnection() {
        super(ServiceConnection.class.getName());
    }

    @Override
    public void onError(int channelId, String errorMessage, int errorCode) {
    }

    @Override
    public void onReceive(int channelId, byte[] data) {
        final String message = new String(data);
        addMessage("Received: ", message);
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                smartwatchPresenter.onMessageReceived(message);
            }
        });
    }

    @Override
    protected void onServiceConnectionLost(int reason) {
        closeConnection();
        smartwatchPresenter.onServiceConnectionLost();
        smartwatchSessionHandler.onServiceDisconnected();
        updateTextView("Disconnected");
    }
}

The accesory services.xml:

<resources>

    <application name="myproject">
        <serviceProfile
            name="myproject"
            id="myproject"
            role="consumer"
            serviceImpl="com.worldline.myproject.app.smartwatch.SmartwatchConsumerService"
            serviceLimit="ANY"
            serviceTimeout="10"
            version="1.0">
            <supportedTransports>
                <transport type="TRANSPORT_BT" />
                <transport type="TRANSPORT_WIFI" />
            </supportedTransports>
            <serviceChannel
                dataRate="low"
                id="104"
                priority="low"
                reliability="enable" />
        </serviceProfile>
    </application>

</resources>
Written by