首页 文章

使用Nearby api无法发现Raspberry pi

提问于
浏览
0

我正在开发一个项目,我必须使用Google的Nearby API在Raspberry pi3(处理Android内容)和Android移动设备之间进行通信 . 我开始在Raspberry pi3上广告服务并成功在移动设备上发现服务 . 但我无法在手机上发现Raspberry pi3 . 这是我的代码 -

Raspberry pi3

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

}

mobile side

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

}

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

1 回答

相关问题