如何从Unity Android应用中打开Android系统设置

时间:2019-03-07 14:22:58

标签: c# android unity3d

我正在尝试从Unity Android应用打开系统设置,但收到以下错误:

  

UnityEngine.AndroidJavaException:   android.content.ActivityNotFoundException:未找到要处理的活动   意图{act = android.settings.ACTION_SETTINGS   cat = [android.intent.category.DEFAULT] dat = package:com.xxx.xxxxx   flg = 0x10000000}

这是我的代码:

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

1 个答案:

答案 0 :(得分:0)

(删除ACTION_)已更改:android.settings.SETTINGS