Notification in Gear2 App

2019-05-31 09:31发布

Is it possible to sent notification from Gear Provide app to Gear Consumer App ?

if possible Please provide a tutorial or sample code for that

2条回答
我想做一个坏孩纸
2楼-- · 2019-05-31 10:14

There doesn't seem to be any way of doing this. The Android "host" app is connected to a "provider" which implies one-way communication.

It is possible with a "push" notification to the Gear app:

Send Notification to Gear 2

Also, it should be possible to send a bluetooth event of some kind (opp / spp) but I can't find anything on that. Same thing with SMS but I haven't seen anything on that.

If I find something I'll edit this post... there seems to be a strong need for thsi.

查看更多
干净又极端
3楼-- · 2019-05-31 10:28

Gear2 notification framework isn't built in as Android wear framework. To do it, you must implement two sides, your Gear2 app and your Android host app.

On your Gear2 app, the tricky part is the javascript callback to accept connection from host-app.

    var agentCallback = {
    onrequest : function(peerAgent) {
        //accept connection if there is a request from host app
        SAAgent.acceptServiceConnectionRequest(peerAgent);
    },
    onconnect : function(socket) {
        console.log("agentCallback onconnect" + socket);

                SASocket = socket;
        SASocket.setDataReceiveListener(onreceive);
        SASocket.setSocketStatusListener(function(reason) {
            console.log("Service connection lost, Reason : [" + reason + "]");
            disconnect();
        });
                //do whatever logic you want like setting up GUI, changing text
    },
    onerror : onerror
};

On Android host app, you must initiate the connection by calling findPeerAgents and when there is a response, request the connection:

@Override
protected void onFindPeerAgentResponse(SAPeerAgent arg0, int arg1) {
    Log.d(TAG, "onFindPeerAgentResponse  arg0 =" + arg0);
    try{
        requestServiceConnection(arg0);
    }catch (Exception e){
        e.printStackTrace();
    }
}

It's a bit lengthy, I detailed it here: https://tungscode.wordpress.com/2014/08/01/send-notification-to-gear2-app/

查看更多
登录 后发表回答