How to Open Android System Settings from Unity Android App

3

I am trying to open the System Settings from my Unity Android app, but I am receiving the following error:

UnityEngine.AndroidJavaException: android.content.ActivityNotFoundException: No Activity found to handle Intent {act =android.settings.ACTION_SETTINGS cat=[android.intent.category.DEFAULT] dat=package:com.xxx.xxxxx flg=0x10000000}

Here is my code:

try
{
    using (var unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    using (AndroidJavaObject currentActivityObject = unityClass.GetStatic<AndroidJavaObject>("currentActivity"))
    {
        string packageName = currentActivityObject.Call<string>("getPackageName");

        using (var uriClass = new AndroidJavaClass("android.net.Uri"))
        using (AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("fromParts", "package", packageName, null))
        using (var intentObject = new AndroidJavaObject("android.content.Intent", "android.settings.ACTION_SETTINGS", uriObject))
        {
            intentObject.Call<AndroidJavaObject>("addCategory", "android.intent.category.DEFAULT");
            intentObject.Call<AndroidJavaObject>("setFlags", 0x10000000);
            currentActivityObject.Call("startActivity", intentObject);
        }
    }
}
catch (Exception e)
{
    Debug.Log(e);
}
c#
android
unity3d
asked on Stack Overflow Mar 7, 2019 by Juned Khan Momin • edited May 30, 2020 by Juned Khan Momin

1 Answer

0

(Remove ACTION_)changed:android.settings.SETTINGS

answered on Stack Overflow Jun 18, 2020 by qianlan cao

User contributions licensed under CC BY-SA 3.0