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);
}
}
}
}
}