Gear2 应用程序中的通知 [英] Notification in Gear2 App

查看:26
本文介绍了Gear2 应用程序中的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 Gear Provide 应用程序向 Gear Consumer 应用程序发送通知?

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

推荐答案

Gear2 通知框架不是作为 Android Wear 框架内置的.为此,您必须实现两个方面,您的 Gear2 应用程序和您的 Android 主机应用程序.

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.

在您的 Gear2 应用程序上,棘手的部分是接受来自主机应用程序的连接的 javascript 回调.

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
};

在 Android 主机应用程序上,您必须通过调用 findPeerAgents 启动连接,并在有响应时请求连接:

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();
    }
}

有点长,我在这里详细说明:https://tungscode.wordpress.com/2014/08/01/send-notification-to-gear2-app/

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

这篇关于Gear2 应用程序中的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆