cancel
Showing results for 
Search instead for 
Did you mean: 

Launcher/Function android.

KhuYam
Honored Guest

Hello everyone. I don't know if it makes sense to write here. According to the forum, no. But I'll try. Guys, I need some help. I'm trying to create a launcher for personal use. Theoretically, it's just a three-dimensional space. Which has a video player, a button, and a timer. That's all!

 

How it should work. I press the button. The timer starts and the installed application opens. The timer ends and the open application closes. This brings us back to my application. I've tried different versions of the code. But that's all I've been able to achieve. This is done in order to open another application. If someone has succeeded. Let me know.

 

I'll leave the code to open the app here. Maybe someone will need it.

 

using UnityEngine;
 
public class Cat : MonoBehaviour
{
    public string targetAppPackageName = "!!!your package name!!!";
 
    public void OnButtonPressed()
    {
        if (Application.isMobilePlatform)
        {
            using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
            {
                AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
                AndroidJavaObject packageManager = currentActivity.Call<AndroidJavaObject>("getPackageManager");
 
                try
                {
                    AndroidJavaObject launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", targetAppPackageName);
                    if (launchIntent != null)
                    {
                        currentActivity.Call("startActivity", launchIntent);
                    }
                    else
                    {
                        Debug.Log("Приложение не установлено.");
                    }
                }
                catch (System.Exception e)
                {
                    Debug.LogError("Ошибка при запуске приложения: " + e.Message);
                }
            }
        }
    }
}
1 ACCEPTED SOLUTION

Accepted Solutions

CaseyAtMeta
Community Manager
Community Manager

I dug around a bit and I'm afraid I have to echo what you've already been told by Support on this—the specific functionality you're looking for isn't something that is currently possible with the way Horizon OS is structured.

You mentioned that you've seen other apps that do the thing you're looking for—can you share which ones you mean? There may be some other developers here on the forum that know of a workaround.

View solution in original post

3 REPLIES 3

KhuYam
Honored Guest

Hi! I'm new to development. I really need some help. I'm trying to create a small app for my kids. It is necessary that when you click on the button, my other, already installed game opens. I've already tried different methods. Nothing is working. The essence of my game is that my son has to complete several tasks. In this case, he will get access to the game. But I can't set up a button with a link. Please help me. If it's not difficult for you, please send the code. Because the neural network helps me write code.

 

I'd like this to work for a while, but I haven't considered that possibility yet. After all, we are responsible for the upbringing of our children, and it is important to regulate the time allocated to computer games.

 

I'm really counting on your help. I have been struggling with this problem for 3 weeks now.

CaseyAtMeta
Community Manager
Community Manager

Thanks for flagging this! I'll share your question around and see if we can get you some direction.

CaseyAtMeta
Community Manager
Community Manager

I dug around a bit and I'm afraid I have to echo what you've already been told by Support on this—the specific functionality you're looking for isn't something that is currently possible with the way Horizon OS is structured.

You mentioned that you've seen other apps that do the thing you're looking for—can you share which ones you mean? There may be some other developers here on the forum that know of a workaround.