简体   繁体   English

Gear2 App中的通知

[英]Notification in Gear2 App

Is it possible to sent notification from Gear Provide app to Gear Consumer App ? 是否可以从Gear Provide应用发送通知到Gear Consumer应用?

if possible Please provide a tutorial or sample code for that 如果可能的话,请提供相应的教程或示例代码

Gear2 notification framework isn't built in as Android wear framework. Gear2通知框架不是作为Android Wear框架内置的。 To do it, you must implement two sides, your Gear2 app and your Android host app. 为此,您必须实现两个方面,即Gear2应用程序和Android主机应用程序。

On your Gear2 app, the tricky part is the javascript callback to accept connection from host-app. 在Gear2应用上,棘手的部分是JavaScript回调,以接受来自主机应用的连接。

    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: 在Android主机应用上,您必须通过调用findPeerAgents来启动连接,并且在有响应时,请请求连接:

@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/ 这有点冗长,我在这里详细介绍: https : //tungscode.wordpress.com/2014/08/01/send-notification-to-gear2-app/

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. Android“主机”应用程序已连接到“提供商”,这意味着单向通信。

It is possible with a "push" notification to the Gear app: 可以向Gear应用程序发送“推送”通知:

Send Notification to Gear 2 发送通知给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. 另外,应该可以发送某种形式的蓝牙事件(opp / spp),但是我找不到任何东西。 Same thing with SMS but I haven't seen anything on that. 与SMS相同,但是我还没有看到任何东西。

If I find something I'll edit this post... there seems to be a strong need for thsi. 如果我发现一些内容,我将编辑这篇文章...似乎强烈需要这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM