API соседних подключений не работает на Android Pie - PullRequest
2 голосов
/ 08 июля 2019

Я установил тестовое приложение для API Nearby Connections от Google. Он отлично работает на Nexus 7 (2012) под управлением Android 4.4.4 и Sony Xperia XZ под управлением Android 8.

Однако, когда я запускаю приложение на своем Pixel 3A под управлением Android 9, я получаю следующее сообщение об ошибке при попытке запустить рекламу в приложении:

"com.google.android.gms.common.api.ApiException: 17: API: Nearby.CONNECTIONS_API недоступно на этом устройстве."

Существует также это сообщение об ошибке, которое происходит до того, как приложение пытается запустить рекламу

"не удалось подключиться к сокету" localabstract: com.jameschamberlain.nearbyconnectionstest ': подключение отклонено "

Любая помощь будет оценена

public void advertise(View v) {
        if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // Permission is not granted
            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
                // Show an explanation to the user *asynchronously* -- don't block
                // this thread waiting for the user's response! After the user
                // sees the explanation, try again to request the permission.
                showLocationExplanation(this, LOCATION_PERMISSION_REQUEST_ADVERTISE);
            } else {
                // No explanation needed; request the permission
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_PERMISSION_REQUEST_ADVERTISE);
            }
        } else {
            // Permission has already been granted
            startAdvertising();
        }
    }


    /**
     * Begin the actual advertising using the Nearby Connections API
     */
    private void startAdvertising() {
        AdvertisingOptions advertisingOptions = new AdvertisingOptions.Builder().setStrategy(Strategy.P2P_STAR).build();
        Nearby.getConnectionsClient(getApplicationContext()).startAdvertising(
                "James",
                SERVICE_ID,
                connectionLifecycleCallback,
                advertisingOptions)
                .addOnSuccessListener(
                        new OnSuccessListener<Void>() {
                            @Override
                            public void onSuccess(Void unusedResult) {
                                // We're advertising!
                                loggingTextView.append("\nAdvertising");
                            }
                        })
                .addOnFailureListener(
                        new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                // We were unable to start advertising.
                                loggingTextView.append("\nNot advertising");
                                loggingTextView.append("\n" + e.toString());
                                Log.e("NearbyError", e.toString());
                            }
                        });
    }
...