cancel
Showing results for 
Search instead for 
Did you mean: 

Android Nearby application not found

Steoberg
Honored Guest

Hello,

I'm trying to create a nearby connection between a Unity VR application on Quest 3 and another Unity app for my android phone.

It works between two phones (older phones, both below Android version 11) but not between Quest and the phones. This is my code so far:

 

[SerializeField] private TextMeshProUGUI MessageText;

    void Awake()
    {
        UpdatePermissions();
        PlayGamesPlatform.InitializeNearby((client) =>
        {
            Advertise();
            Discover();
        });
    }

    private void UpdatePermissions()
    {
#if UNITY_ANDROID

        string[] permissions = new string[]
        {
            "android.permission.ACCESS_WIFI_STATE",
            "android.permission.CHANGE_WIFI_STATE",
            "android.permission.BLUETOOTH_ADMIN",
            "android.permission.ACCESS_COARSE_LOCATION",
            "android.permission.ACCESS_FINE_LOCATION",
            "android.permission.BLUETOOTH_ADVERTISE",
            "android.permission.BLUETOOTH_CONNECT",
            "android.permission.BLUETOOTH_SCAN",
            "android.permission.NEARBY_WIFI_DEVICES"
        };

        bool needsPermission = false;
        foreach (string permission in permissions)
        {
            if (!Permission.HasUserAuthorizedPermission(permission))
            {
                needsPermission = true;
            }
        }
        if (needsPermission)
        {
            Permission.RequestUserPermissions(permissions);
        }
#endif
    }

    private void Advertise()
    { 
        Log("Start advertising");
        List<string> appIdentifiers = new List<string>();
        appIdentifiers.Add(PlayGamesPlatform.Nearby.GetAppBundleId());
        PlayGamesPlatform.Nearby.StartAdvertising(
                   "App",
                    appIdentifiers,
                   TimeSpan.FromSeconds(0),
                   (AdvertisingResult result) =>
                   {
                       Log("OnAdvertisingResult: " + result.Status);
                   },
                      (ConnectionRequest request) =>
                      {
                          Log("Received connection request: " +
                       request.RemoteEndpoint.EndpointId + " " +
                       request.RemoteEndpoint.Name);


                      }
                   );
    }

    private void Discover()
    {
        Log("Start discovering");
        PlayGamesPlatform.Nearby.StartDiscovery(
                PlayGamesPlatform.Nearby.GetServiceId(),
                TimeSpan.FromSeconds(0),
                this);
    }

    public void OnEndpointFound(EndpointDetails discoveredEndpoint)
    {
        Log("Enpoint found: " + discoveredEndpoint.EndpointId + " " + discoveredEndpoint.Name);
    }

    public void OnEndpointLost(string lostEndpointId)
    {
        Log("Enpoint lost: " + lostEndpointId);
    }


    private void Log(string msg)
    {
        MessageText.text += msg + "\n";
    }

 

My AndroidManifest.xml permission (in the Editor):

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
  <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
  <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
  <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />

 

The generated AndroidManifest.xml after building (from unityLibrary/src/main):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" xmlns:tools="http://schemas.android.com/tools">
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
  <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
  <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
  <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />
  <uses-feature android:glEsVersion="0x00030000" />
  <uses-feature android:name="android.hardware.vulkan.version" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
  <application android:extractNativeLibs="true">
    <meta-data android:name="unity.splash-mode" android:value="0" />
    <meta-data android:name="unity.splash-enable" android:value="True" />
    <meta-data android:name="unity.launch-fullscreen" android:value="True" />
    <meta-data android:name="unity.allow-resizable-window" android:value="False" />
    <meta-data android:name="notch.config" android:value="portrait|landscape" />
    <meta-data android:name="unity.auto-report-fully-drawn" android:value="true" />
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector" android:screenOrientation="fullUser" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:resizeableActivity="false" android:hardwareAccelerated="false" android:exported="true">
      <intent-filter>
        <category android:name="android.intent.category.LAUNCHER" />
        <action android:name="android.intent.action.MAIN" />
        <category android:name="com.oculus.intent.category.VR" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
      <meta-data android:name="notch_support" android:value="true" />
    </activity>
  </application>
</manifest>

 

Nearby initialized successfully but it never finds another endpoint.

Any idea?

Thanks!

0 REPLIES 0