Notification in Gear2 App

穿精又带淫゛_ 提交于 2019-12-08 06:38: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


回答1:


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/




回答2:


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.



来源:https://stackoverflow.com/questions/24305213/notification-in-gear2-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!