Hello there Magic Leap community,
I'm currently trying to host a small web server within my Unity App to allow accessing a debug interface by directly connecting to the ML via a web browser.
I'm running into an issue where I can't seem to figure out how get the required permissions for accessing a folder previously copied to the device.
Things I have done so far:
- add
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
to the manifest file. - check required permissions during app startup and request them via the ML SDK interface if not present (app shows up with storage permissions in the permission manager after initially approving).
- tried different location within the
/sdcard
directory.
Sadly, the web server always returns a 404 error as the read operation on the directory which should be served fails (see error below).
Admittedly I'm not very experienced with Android development but as far as I understand, the external storage should be an alias for everything within the /sdcard
folder on the device or am I getting this wrong?
Thank you in advance!
Unity Editor version: 2022.2.0b16
ML2 OS version: 1.1.0
MLSDK version: 1.2.0
Host OS: Windows
Error messages from logs (syntax-highlighting is supported via Markdown):
System.UnauthorizedAccessException: Access to the path "/sdcard/Public/debug-client/index.html" is denied.
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00000] in <00000000000000000000000000000000>:0
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions options) [0x00000] in <00000000000000000000000000000000>:0
at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize) [0x00000] in <00000000000000000000000000000000>:0
at System.IO.File.InternalReadAllText (System.String path, System.Text.Encoding encoding) [0x00000] in <00000000000000000000000000000000>:0
at Websockets.Server.DebugServer+<>c__DisplayClass5_0.<.ctor>b__0 (System.Object sender, WebSocketSharp.Server.HttpRequestEventArgs e) [0x00000] in <00000000000000000000000000000000>:0
at WebSocketSharp.Server.HttpServer.processRequest (WebSocketSharp.Net.HttpListenerContext context) [0x00000] in <00000000000000000000000000000000>:0
at WebSocketSharp.Server.HttpServer+<>c__DisplayClass87_0.<receiveRequest>b__0 (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <00000000000000000000000000000000>:0
The manifest file:
<?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">
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
<uses-permission android:name="com.magicleap.permission.SPATIAL_MAPPING" />
<uses-permission android:name="com.magicleap.permission.SPATIAL_ANCHOR" />
<uses-permission android:name="com.magicleap.permission.HAND_TRACKING" />
<uses-permission android:name="com.magicleap.permission.WEBVIEW" />
<uses-permission android:name="com.magicleap.permission.MARKER_TRACKING" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="com.magicleap.permission.VOICE_INPUT" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
Mono Behaviour permissions snippet:
void Start()
{
if (MLPermissions.CheckPermission(MLPermission.ReadExternalStorage).IsOk)
{
InitServer();
}
else
{
MLPermissions.RequestPermission(MLPermission.ReadExternalStorage, permissionCallbacks);
}
}