# Connecting the glasses in Android

It seems to be a chore at first and depending on your phone, it might or might not work.  
Don't look into "desktop mode" etc.   
  
Issue logged [here](https://support.google.com/android/thread/432370422?hl=en&sjid=2250387810553078903-EU)

<div id="bkmrk-pixel-8-has-this-tog">  
<span style="text-decoration: underline;">**Pixel 8**</span> has this toggle in settings "External displays" - and you have to set the checkbox every time you connect.  
<span style="text-decoration: underline;">**Xperia 5** </span>does not have this toggle.</div><div id="bkmrk-">  
</div><div id="bkmrk--1">  
</div>#### Automatic route:

<div id="bkmrk-install-the-apk-and-">Install the APK and via adb</div><div id="bkmrk--2"></div><div id="bkmrk-c%3A%5Cusers%5Ctim%5Cappdata">C:\Users\Tim\AppData\Local\Android\Sdk\platform-tools&gt;</div><div id="bkmrk--3"></div>```
adb shell pm grant com.sophior.screenenabler android.permission.WRITE_SECURE_SETTINGS
adb shell pm grant com.sophior.screenenabler android.permission.DUMP
```

<div id="bkmrk--4">  
</div><div id="bkmrk--5">  
</div>#### Manual route;

<div id="bkmrk-analyzing-via-adb-%28v">  
  
Analyzing via adb (via wireless debugging), it is this action that is required:</div><div id="bkmrk--6">  
</div>```
adb shell cmd display enable-display 139
```

<div id="bkmrk--7">  
</div><div id="bkmrk-you-can-find-the-dis">You can find the display id via this one:</div>```
adb shell cmd display get-displays
```

<div id="bkmrk--8">  
</div><div id="bkmrk-if-it-is-not-listed-">If it is not listed find it here:</div>```
adb shell dumpsys display | findstr /i "XREAL HDMI EXTERNAL mDisplayId mIsEnabled state OFF DisplayViewport"
```

<div id="bkmrk--9">  
</div><div id="bkmrk-then%2C-the-android-wi">Then, the Android will prompt to "Allow display over other apps", when enabled, the glasses will start up and I can read the parameters in the headtracking and have a 3D app.  
When I exit the app, there is the mirroring of Android.</div><div id="bkmrk--10">  
</div><div id="bkmrk--11">  
</div><div id="bkmrk-i-made-this-script%2C-">I made this script, but it requires to be connected to the Android phone with adb:</div><div id="bkmrk--12">  
</div>```
$adb = "$env:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe"<br></br>$dump = & $adb shell dumpsys display<br></br>$displayId = $null<br></br>$currentId = $null<br></br>$inExternalBlock = $false<br></br>$isXreal = $false<br></br>$isDisabled = $false<br></br>foreach ($line in $dump) {<br></br>    if ($line -match 'mDisplayId=(\d+)') {<br></br>        $currentId = $matches[1]<br></br>        $inExternalBlock = $false<br></br>        $isXreal = $false<br></br>        $isDisabled = $false<br></br>    }<br></br>    if ($line -match 'type EXTERNAL|type=EXTERNAL|mPrimaryDisplayDevice=HDMI Screen|mPrimaryDisplayDevice=XREAL') {<br></br>        $inExternalBlock = $true<br></br>    }<br></br>    if ($line -match 'XREAL One Pro|HDMI Screen') {<br></br>        $isXreal = $true<br></br>    }<br></br>    if ($line -match 'mIsEnabled=false|state OFF|committedState OFF') {<br></br>        $isDisabled = $true<br></br>    }<br></br>    if ($currentId -and $inExternalBlock -and $isXreal -and $isDisabled) {<br></br>        $displayId = $currentId<br></br>        break<br></br>    }<br></br>}<br></br><br></br>if (-not $displayId) {<br></br>    Write-Host "No disabled XREAL/external display found."<br></br>    exit 1<br></br>}<br></br><br></br>Write-Host "Enabling external display ID $displayId..."<br></br>& $adb shell cmd display enable-display $displayId<br></br>& $adb shell input keyevent KEYCODE_WAKEUP<br></br><br></br>Write-Host "Done."
```