【问题标题】:Cannot discover Raspberry pi using Nearby api无法使用 Nearby api 发现 Raspberry pi
【发布时间】:2017-12-25 01:51:36
【问题描述】:

我正在开展一个项目,我必须使用 Google 的 Nearby API 在 Raspberry pi3(处理 Android 事物)和 android mobile 之间进行通信。我成功地在树莓派 3 上启动了广告服务,并在移动设备上成功地启动了发现服务。但我无法在我的手机上发现 Raspberry pi3。这是我的代码-

树莓派3上:

private void startAdvertizing() {

    logging("advertizing initiated");



    Nearby.Connections.startAdvertising(mCLient,"Tinku",getString(R.string.service_id),mConnectionLifecycleCallback
                                        ,new AdvertisingOptions(Strategy.P2P_CLUSTER)).setResultCallback(new ResultCallback<Connections.StartAdvertisingResult>() {
        @Override
        public void onResult(@NonNull Connections.StartAdvertisingResult startAdvertisingResult) {
            if (startAdvertisingResult.getStatus().isSuccess()){
                logging("avertizind success");
            } else {
                logging(startAdvertisingResult.getStatus().getStatusMessage());
            }
        }
    });

}

移动端

 private void startDicovery() {
    Log.d(TAG,"Initializing discovery");
    tv.setText("Initializing discovery");

    EndpointDiscoveryCallback mEndPointDiscoveryCallback = new EndpointDiscoveryCallback() {
        @Override
        public void onEndpointFound(String s, DiscoveredEndpointInfo discoveredEndpointInfo) {
            Log.d(TAG,"Endpoint found");
            tv.setText("Endpoint found");
        }

        @Override
        public void onEndpointLost(String s) {
            Log.d(TAG,"Endpoint Lost, "+s);
            tv.setText("Endpoint Lost, "+s);
        }
    };


    Nearby.Connections.startDiscovery(mCLient,getString(R.string.service_id),mEndPointDiscoveryCallback,new DiscoveryOptions(Strategy.P2P_CLUSTER))
                        .setResultCallback(new ResultCallback<Status>() {
                            @Override
                            public void onResult(@NonNull Status status) {
                                if (status.isSuccess()){
                                    logging("Discovert success");
                                    isDiscovery = true;
                                } else {
                                    logging("Discovery failed "+ status.getStatusMessage());
                                    isDiscovery = false;
                                }
                            }
                        });

}

我不知道我错过了什么。任何帮助将不胜感激。

【问题讨论】:

    标签: android google-api raspberry-pi3 android-things google-nearby


    【解决方案1】:

    嗯,我以前见过这种方法。您可以尝试几件事。

    1) 检查日志。见Is it possible to monitor discovering process when using Google Nearby Connections 2.0?

    2) 在两部 Android 手机上试一试,以确保代码有效。 sn-ps 看起来不错,但你永远不知道。

    3) 将您的手机和 Android Things 设备的型号和 Android 操作系统构建版本发送给我。

    【讨论】:

    • 当我搜索特定的服务 id 时它工作了,但它对我的项目来说已经足够了。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多