Hi!
I am very new to Android development and have set up a minimal project where I want to launch a new Activity from the Unity Activity running on quest/quest2 using an Android Java proxy class. The issue I am facing is that when i try to launch the new activity i get the “three loading dots” on the oculus headset and it stays there until I hit the home screen button returning me to the Oculus lobby. I can see that the plugin code is running my System.out.println in the Logcat but for some reason it will not display the simple layout related to the Activity.
The plugin is exported as an AAR and put in the …\Assets\Plugins\Android\libs path of the Unity project.
Unity class calling plugin:
public class NativeCall : MonoBehaviour
{
public void CalleNativePlugin()
{
#if !UNITY_EDITOR
CalleNativePluginPrivate();
#endif
}
private void CalleNativePluginPrivate()
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject plugin = new AndroidJavaObject("com.example.minimumproduct.Proxy");
plugin.CallStatic("CreateActivity", currentActivity);
}
}
Proxy class:
As commented in this part of the code it will start a new Activity displaying the Oculus browser when i create it as an implicit Intent but not when the Intent is created with my own class.
package com.example.minimumproduct;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
public class Proxy {
public static void CreateActivity(Activity activity)
{
System.out.println("Creating activity");
// Below is NOT working and gives the "three dots" ->
Intent myIntent = new Intent(activity, MainActivity.class);
// Below is working and opens a browser ->
//Uri uri = Uri.parse("http://google.com");
// Intent myIntent = new Intent(Intent.ACTION_VIEW, uri);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.startActivity(myIntent);
}
});
}
}
MainActivity Class:
package com.example.minimumproduct;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("On create was called");
}
}
When I deploy the application as a standalone app (not launching through Unity) on the quest it launches my Activity and displays my layout perfectly fine. This makes me believe that it has something to do with not exiting the fullscreen VR-mode and not being able to make the transition to display my “2D”-layout.
Ive been running it in several different configurations and cannot seem to get it working. One of the messages from logcat that may have some relevance to this is:
W ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@16ea560
But from the posts I have read regarding this i do not understand if it in fact relates to my issues.
Yes, I tried to update the Unity and Oculus integration to the latest versions, but the result is the same.
As an experiment, I tried to call a function from my Android Native Plugin, which should display a regular Android Toast, but it also doesn’t work out (doesn’t appear). But if call a simple function implemented in the plugin (e.x. multiplication function), then the logs contain the result of its execution. That is, the plugin is connected and working =(
Unfortunetaly not.
I, like you did, could also verify the plugin was working logically, it was the part of displaying the new activity that was failing.
Br
/Robin
Did you also update the Oculus XR plugin to the latest version manually? (preferably pre-release)
And make sure in XR Management, under android ‘start XR on startup’ is on and Oculus is selected under the android tab
Hmm weird bugs. Updated Unity to the latest v? If so, make a bug report (:
You can also try to download the VR preset and see if that works and then continue from there
Perhaps the problem lies in the logs, but I’m in the Unity recently and I couldn’t google where to dig.
This is logs, when I try to start Android Activity from my Test plugin
Yes, this is my main task to launch a native Android app (specially edited) on the Oculus Quest 2.
I am doing minimal research on this matter, created a primitive native Android Kotlin plugin and launched it just on the Oculus using Unity. Everything works.
Build project for Oculus and got the problem described above =(
Since the Oculus has an Android OS (with some restrictions) and there was a request from management to try to run a native Android app on it.
I managed to launch the native Android app on the Oculus without any problems, but in windowed mode. And the task arose to get rid of the windowed mode. And for this it is necessary to build the project under the Oculus.
P.s. I have a lot of experience in writing native apps, but I’ve been dealing with Unity for about a week =)
Hi!
I needed to abandon the original idea. No matter what I tried, I could not get it working displaying my new activity on the Oculus Quest.
For my use case it was not absolutely necessary (but preferable) if it would have worked but there were ways I could achieve my goal from within Unity.
Got it, it’s a pity that it didn’t work. Also decided to abandon this concept. It remains to explain it to management =)
Perhaps today I found the reason for this behavior (mobile-vrapi):
“Multiple Android activities that live in the same address space can cooperatively use the VrApi. However, only one activity can be in VR mode at a time.”
Maybe not, but it looks like our case.
first of all, you should check for the XR plugin management is installed or not, if it is installed please ensure the check mark in front of the oculus is checked. and try to build it if still, you are facing the same issue then check for particular scenes and if there is any script in that scene make sure there is no error in that, and in the last change the project name. you issue should resolve by this.
[quote=kumarashwin2522]
first of all, you should check for the XR plugin management is installed or not, if it is installed please ensure the check mark in front of the oculus is checked.
[/quote]