1,打开安卓设备不同的设置面板,我还贴心的把Android官网的链接放下面了
2,使用也很方便:unity按钮事件上拖这个脚本,注册MyOpenAndroidSettings方法,参数 填 和枚举值相应的数字
//
功能:打开安卓设备不同的设置面板//
//
using UnityEngine;
using UnityEngine.UI;public class OpenAndroidSettingsPanel : MonoBehaviour
{AndroidJavaObject currentActivity; //Android 官方文档 执行各种操作和打开不同的设置面板 的链接//https://developer.android.com/about/versions/12/reference/common-intents-31?hl=zh-cnpublic enum AndroidSettingsPanel{HOME_SETTINGS,//设置启动器SETTINGS,//设置面板WEB_SEARCH,//浏览器WIFI_SETTINGS,//Wi-Fi 设置面板BLUETOOTH_SETTINGS, //蓝牙设置面板DATA_ROAMING_SETTINGS, //移动网络设置面板APPLICATION_SETTINGS,//应用程序管理设置面板DISPLAY_SETTINGS,//显示设置面板DATE_SETTINGS,//日期和时间设置面板INPUT_METHOD_SETTINGS,//语言和输入法设置面板LOCATION_SOURCE_SETTINGS,//位置设置面板INTERNAL_STORAGE_SETTINGS,//存储设置面板NOTIFICATION_SETTINGS,//通知设置面板IGNORE_BATTERY_OPTIMIZATION_SETTINGS,//电池优化设置面板ACCESSIBILITY_SETTINGS,//无障碍服务设置面板NETWORK_OPERATOR_SETTINGS,//移动网络运营商设置面板SOUND_SETTINGS,//声音设置面板SECURITY_SETTINGS,//安全设置面板}#region 测试int index;public InputField inputField;/// <summary>/// 打开相应的设置面板/// </summary>public void MyOpenAndroidSettings(){string action = SetAction(index);// 创建一个Android的Intent对象,并指定要启动的ActivityAndroidJavaObject intentObj = new AndroidJavaObject("android.content.Intent");intentObj.Call<AndroidJavaObject>("setAction", action);// 启动ActivitycurrentActivity.Call("startActivity", intentObj);}#endregionprivate void Start(){#region 测试inputField.onEndEdit.AddListener((str) =>{index = int.Parse(str);Debug.Log(index);});#endregion// 获取Unity的当前活动(Activity)对象AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");}/// <summary>/// 设置action/// </summary>string SetAction(int androidSettingsPanel){switch ((AndroidSettingsPanel)androidSettingsPanel){case AndroidSettingsPanel.HOME_SETTINGS:return "android.settings.HOME_SETTINGS";case AndroidSettingsPanel.SETTINGS:return "android.settings.SETTINGS";case AndroidSettingsPanel.WEB_SEARCH:return "android.intent.action.WEB_SEARCH";case AndroidSettingsPanel.WIFI_SETTINGS:return "android.settings.WIFI_SETTINGS";case AndroidSettingsPanel.BLUETOOTH_SETTINGS:return "android.settings.BLUETOOTH_SETTINGS";case AndroidSettingsPanel.DATA_ROAMING_SETTINGS:return "android.settings.DATA_ROAMING_SETTINGS";case AndroidSettingsPanel.APPLICATION_SETTINGS:return "android.settings.APPLICATION_SETTINGS";case AndroidSettingsPanel.DISPLAY_SETTINGS:return "android.settings.DISPLAY_SETTINGS";case AndroidSettingsPanel.DATE_SETTINGS:return "android.settings.DATE_SETTINGS";case AndroidSettingsPanel.INPUT_METHOD_SETTINGS:return "android.settings.INPUT_METHOD_SETTINGS";case AndroidSettingsPanel.LOCATION_SOURCE_SETTINGS:return "android.settings.LOCATION_SOURCE_SETTINGS";case AndroidSettingsPanel.INTERNAL_STORAGE_SETTINGS:return "android.settings.INTERNAL_STORAGE_SETTINGS";case AndroidSettingsPanel.NOTIFICATION_SETTINGS:return "android.settings.NOTIFICATION_SETTINGS";case AndroidSettingsPanel.IGNORE_BATTERY_OPTIMIZATION_SETTINGS:return "android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS";case AndroidSettingsPanel.ACCESSIBILITY_SETTINGS:return "android.settings.ACCESSIBILITY_SETTINGS";case AndroidSettingsPanel.NETWORK_OPERATOR_SETTINGS:return "android.settings.NETWORK_OPERATOR_SETTINGS";case AndroidSettingsPanel.SOUND_SETTINGS:return "android.settings.SOUND_SETTINGS";case AndroidSettingsPanel.SECURITY_SETTINGS:return "android.settings.SECURITY_SETTINGS";}return null;}/// <summary>/// 打开相应的设置面板/// </summary>public void MyOpenAndroidSettings(int androidSettingsPanel){string action = SetAction(androidSettingsPanel);// 创建一个Android的Intent对象,并指定要启动的ActivityAndroidJavaObject intentObj = new AndroidJavaObject("android.content.Intent");intentObj.Call<AndroidJavaObject>("setAction", action);// 启动ActivitycurrentActivity.Call("startActivity", intentObj);}/// <summary>/// 打开日历面板/// </summary>public void MyOpenCalendarPanel(){AndroidJavaObject intentObj = new AndroidJavaObject("android.content.Intent");intentObj.Call<AndroidJavaObject>("setAction", "android.intent.action.MAIN");intentObj.Call<AndroidJavaObject>("addCategory", "android.intent.category.APP_CALENDAR");intentObj.Call<AndroidJavaObject>("setFlags", 0x10000000); // Intent.FLAG_ACTIVITY_NEW_TASKcurrentActivity.Call("startActivity", intentObj);}
}