目录
1.先上最终研究成果(unity已经提供了面向Android的 权限申请方法)
2.疑难问题
3.原理解析:
1.先上最终研究成果(unity已经提供了面向AndroID的 权限申请方法)
ex:UnityEngine.AndroID.Permission.RequestUserPermission(s);
重要提示:使用unity的动态权限申请可以动态的d出是否同意该权限界面,方便了很多
string[] strs=new string[] { "androID.permission.INTERNET", "androID.permission.READ_PHONE_STATE", "androID.permission.READ_EXTERNAL_STORAGE", "androID.permission.WRITE_EXTERNAL_STORAGE", "androID.permission.ACCESS_WIFI_STATE", "androID.permission.ACCESS_NETWORK_STATE", "androID.permission.GET_TASKS", "androID.permission.REQUEST_INSTALL_PACKAGES", "androID.permission.WAKE_LOCK", "androID.permission.SYstem_ALERT_WINDOW", "androID.permission.CHANGE_WIFI_STATE", "androID.permission.CHANGE_NETWORK_STATE", "androID.permission.ACCESS_COARSE_LOCATION", "androID.permission.ACCESS_FINE_LOCATION", "androID.permission.SYstem_OVERLAY_WINDOW", "androID.permission.ACCESS_COARSE_UPDATES", "androID.permission.WRITE_SETTINGS", "androID.permission.BATTERY_STATS", "androID.permission.MOUNT_UNMOUNT_fileSYstemS" }; // Use this for initialization voID Start () { DeBUG.Log("start main"); // var iscon= PlayerConnection.instance.isConnected; strs.ToList().ForEach(s=>{ //DeBUG.Log("RequestUserPermission: "+s); //if (!Permission.HasUserAuthorizedPermission(s)) //{ Permission.RequestUserPermission(s); DeBUG.Log("add RequestUserPermission: " + s); //} //else //{ // DeBUG.Log("it has RequestUserPermission: " + s); //} }); //UnityEngine.Networking.PlayerConnection.PlayerConnection. //实例化上下文环境 // adUnionContext = AdUnionContext.GetInstance(); ////初始化SDK //AdUnionSDK.Init(APP_ID, new OnAuInitListenerProxy()); ////初始化unity自带的控件 initComponents(); }
2.疑难问题中间遇到的问题,配置在AndroIDManifest.xml中的权限有时候会导致不能动态申请到所需权限,所以可以全部注释掉,然后动态添加。
3.原理解析:
其实调用的是AndroID方法
com.example.androIDpermissionmgr.PermissionProvIDer 中的verifyPermissions方法
#if UNITY_ANDROID private AndroIDJavaClass _request; public AndroIDJavaClass Request { get { if (_request == null) _request = new AndroIDJavaClass ("com.example.androIDpermissionmgr.PermissionProvIDer"); return _request; } } #else public voID RequestPermissions (int requestCode, params string[]permissions) { DeBUG.Log ("[PermissionProvIDer] Requesting permissions: "+ requestCode + " " + permissions ); Request.CallStatic ("verifyPermissions", gameObject.name, requestCode, permissions); }
@H_403_51@ 总结 以上是内存溢出为你收集整理的Unity2019中的android动态申请权限(Permissions)全部内容,希望文章能够帮你解决Unity2019中的android动态申请权限(Permissions)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)