Background service unable to find files in specified directory on Magic Leap 2

Hello Community,

I've run into an issue while developing an application for the Magic Leap 2. I've developed an Android background service for a Unity app. This service uploads .mp4 files to Google Cloud Storage (GCS).

When I use this Unity sample app as an archive package on standard Android devices, it successfully uploads files from the specified directory to GCS. However, when I try to use this same Unity sample app on Magic Leap 2, the service fails to upload the videos. It seems that the service is unable to find any files in the specified directory.

Console Logs:

Service is properly starting:

Test 1:

Test 2:

Magic Leap Storage:

I'm hoping someone here can help shed light on this issue.

Unity Editor version: 2022-2.0f1
ML2 OS version: 1.3.0-dev2
MLSDK version: 1.7.0
Host OS: Windows 11

I haven't received any explicit error messages in the logs regarding this issue.

For the sake of understanding, I am able to upload files using firebase unity SDK. But I am using android background service to actively upload files in the background to save time.

Thank you in advance for any help or guidance you can provide.

@usman.bashir We use the stock Android API to manage our background services.

To test your plugin, I recommend compiling a standard Android Unity test app and testing it using the Android Studio using the Android Emulator, then on the device.

  1. Create a new Unity project to isolate the test you are performing. In this case, testing the plugin that uploads files as a background service.
  2. Set the player settings to Android and target x86_64. Do not include the Magic Leap SDK
  3. Build the standard android Application.
  4. In Android Studio, create an x86_64 virtual device that runs Android 10, without google play services.
  5. Deploy your Unity app to the virtual device and verify the functionality.
  6. Finally, verify the functionality on Magic Leap 2 by installing the standard android application. It will launch as a 2D application.

Running this test will help identify if the issue is due to the plugin or the Magic Leap OS.

I found this open source project that might be able to help : GitHub - nintendaii/unity-background-service: A simple project that shows how to create an Android service for Unity application working on background

@kbabilinski,

Thank you for your guidance. To confirm, I have exactly performed the steps you've recommended.

I created two separate projects:

  1. One for Android Studio and
  2. The other one as a Unity sample app (without using the Magic Leap SDK).

The Android Studio project is used to develop the background service. After its completion, I tested it on an emulator created within Android Studio. The service was working correctly and was able to upload video files without any issues. I further verified the functionality by installing the same app on a standard Android testing device, where it also worked perfectly.

The Unity project is created to use the module developed in Android Studio as an archive package. I ensured that this Unity project was a simple sample app that doesn't involve any Magic Leap SDK. As per the results from my Android testing, the app is able to successfully upload video files to Google Cloud Storage (GCS).

However, when I installed this Unity app on a Magic Leap 2 device, the service failed to find the files it was supposed to upload. I did not receive any explicit error message, just a warning that the file was not found.

In summary:

  1. The Android Studio project works perfectly on both an emulator and a standard Android device.
  2. The Unity project works on standard Android devices. (without using the Magic Leap SDK)
  3. The same Unity app fails to locate files on Magic Leap 2, resulting in an inability to upload files to GCS.

I am uncertain about what might be causing this discrepancy in file location and access between standard Android devices and Magic Leap 2.

Thank you for that information, I will report this internally and try to get it resolved as soon as possible.

@usman.bashir I sent you a PM . Do you have an apk of the working 2D app that we can test on our end ?

Dear @kbabilinski,

I will be able to send you the application for testing soon. However, in preparation for this, there are a few steps you need to undertake on your Android device:

  1. Create a new directory within the 'DCIM' folder. Please name this directory 'ConceptHealth'.
  2. Once the 'ConceptHealth' directory is created, place your MP4 files into this directory.

These actions are necessary to ensure the app operates correctly during your testing phase. I appreciate your cooperation and look forward to your feedback on the application.

Dear @kbabilinski,

I will be able to send you the application for testing soon. However, in preparation for this, there are a few steps you need to undertake on your Android device:

  1. Create a new directory within the 'DCIM' folder. Please name this directory 'ConceptHealth'.
  2. Once the 'ConceptHealth' directory is created, place your MP4 files into this directory.

Note: When you are opening the application for the first time, Please enable user permission settings manually from App Info Settings.

These actions are necessary to ensure the app operates correctly during your testing phase.

Here is my implementation and I am able to see logs of Android background service in Unity Console.

2023/07/24 23:30:58.260 9960 9960 Debug VideoUploadService Video upload success. Download URL: https://firebasestorage.googleapis.com/v0/b/aconsult.appspot.com/o/videos%2Ftitle-artist.mp4?alt=media&token=6ac60896-227d-4a58-ab57-adbab7c3ba2e
2023/07/24 23:31:20.702 9960 9960 Debug VideoUploadService Video upload success. Download URL: https://firebasestorage.googleapis.com/v0/b/aconsult.appspot.com/o/videos%2Fmagic-leap-2-outdoor-testing-with-global-dimming.mp4?alt=media&token=6174272f-e0bd-4c48-a253-3366258cb3ca

Snapshot of Unity Console:

@kbabilinski Here is the Unity APK without Magic Leap SDK. You can download APK:

@usman.bashir Can you make sure the apk you sent was compiled for the x86_64 platform?

@kbabilinski Apologies for a bit delay. I was investigating WebRTC related issues.

I am able to make the required APK for you. Here are my testing results using Android Emulator:

Here you can find APK:

To make sure I understand the expected log “no files found in concept health folder?” However on the Magic Leap you get a missing folder error?

  • To make sure I understand the expected log “no files found in concept health folder?” However on the Magic Leap you get a missing folder error?

I am getting error "no files found in ConceptHealth Folder" while I am running this app in Magic Leap 2 device.

The screenshot you posted shows the “content not found” log message. Was the screenshot taken when you we’re connected to the emulator or to the Magic Leap. Can you confirm that the application works properly in the emulator?

This screenshot was taken when I was connected to ML2 device.

The APK you sent gets the same error when using the Android Emulator suggesting that this is an Android based issue. Since it is not specific to Magic Leap 2 it is outside the scope of this forum, but I recommend investigating how to access a file or folder outside an applications local data.