public void RegisterSensorListener(SENSOR_TYPE type, SENSOR_LOCATION location) { if (nibiruSensorServiceObject != null) { if (nibiruSensorDataListenerCallback == null) { nibiruSensorDataListenerCallback = new NibiruSensorDataListenerCallback(); } // UI线程执行 RunOnUIThread(androidActivity, new AndroidJavaRunnable(() => { AndroidJavaClass locationClass = BaseAndroidDevice.GetClass("com.nibiru.service.NibiruSensorService$SENSOR_LOCATION"); AndroidJavaObject locationObj = locationClass.CallStatic <AndroidJavaObject>("valueOf", location.ToString()); AndroidJavaClass typeClass = BaseAndroidDevice.GetClass("com.nibiru.service.NibiruSensorService$SENSOR_TYPE"); AndroidJavaObject typeObj = typeClass.CallStatic <AndroidJavaObject>("valueOf", type.ToString()); nibiruSensorServiceObject.Call <bool>("registerSensorListener", typeObj, locationObj, nibiruSensorDataListenerCallback); Debug.Log("registerSensorListener=" + type.ToString() + "," + location.ToString()); } )); } else { Debug.LogError("RegisterControllerSensor failed, nibiruSensorServiceObject is null !"); } }
//4.1 获取屏幕亮度值: /// <summary> /// Get system's brightness value /// </summary> /// <returns></returns> public int GetBrightnessValue() { int BrightnessValue = 0; #if UNITY_ANDROID BaseAndroidDevice.CallObjectMethod <int>(ref BrightnessValue, nibiruOsServiceObject, "getBrightnessValue"); #endif return(BrightnessValue); }
//4.2 调节屏幕亮度: /// <summary> /// Set system's brightness value /// </summary> /// <returns></returns> public void SetBrightnessValue(int value) { if (nibiruOsServiceObject == null) { return; } #if UNITY_ANDROID RunOnUIThread(androidActivity, new AndroidJavaRunnable(() => { BaseAndroidDevice.CallObjectMethod(nibiruOsServiceObject, "setBrightnessValue", value, 200.01f); })); #endif }
public void Init() { #if UNITY_ANDROID try { using (AndroidJavaClass player = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { androidActivity = player.GetStatic <AndroidJavaObject>("currentActivity"); audioManager = androidActivity.Call <AndroidJavaObject>("getSystemService", new AndroidJavaObject("java.lang.String", "audio")); } } catch (AndroidJavaException e) { androidActivity = null; Debug.LogError("Exception while connecting to the Activity: " + e); return; } nibiruSDKClass = BaseAndroidDevice.GetClass(NibiruSDKClassName); // // systemDevice = nibiruSDKClass.CallStatic<string>("getSystemProperty", "ro.product.device", ""); nibiruOsServiceObject = nibiruSDKClass.CallStatic <AndroidJavaObject>("getNibiruOSService", androidActivity); nibiruSensorServiceObject = nibiruSDKClass.CallStatic <AndroidJavaObject>("getNibiruSensorService", androidActivity); nibiruVoiceServiceObject = nibiruSDKClass.CallStatic <AndroidJavaObject>("getNibiruVoiceService", androidActivity); nibiruGestureServiceObject = nibiruSDKClass.CallStatic <AndroidJavaObject>("getNibiruGestureService", androidActivity); nibiruVRServiceObject = nibiruSDKClass.CallStatic <AndroidJavaObject>("getUsingNibiruVRServiceGL"); nibiruCameraServiceObject = nibiruSDKClass.CallStatic <AndroidJavaObject>("getNibiruCameraService", androidActivity); nibiruMarkerServiceObject = nibiruSDKClass.CallStatic <AndroidJavaObject>("getNibiruMarkerService", androidActivity); HMDCameraId = nibiruCameraServiceObject.Call <int>("getHMDCameraId"); ControllerCameraId = nibiruCameraServiceObject.Call <int>("getControllerCameraId"); UpdateVoiceLanguage(); // Debug.Log("nibiruOsServiceObject is "+ nibiruOsServiceObject.Call<AndroidJavaObject>("getClass").Call<string>("getName")); // Debug.Log("nibiruSensorServiceObject is " + nibiruSensorServiceObject.Call<AndroidJavaObject>("getClass").Call<string>("getName")); NibiruTask.NibiruTaskApi.Init(); IsCaptureEnabled = -1; // 默认触发请求权限: RequsetPermission(new string[] { NxrGlobal.Permission.CAMERA, NxrGlobal.Permission.WRITE_EXTERNAL_STORAGE, NxrGlobal.Permission.READ_EXTERNAL_STORAGE, NxrGlobal.Permission.ACCESS_NETWORK_STATE, NxrGlobal.Permission.ACCESS_COARSE_LOCATION, NxrGlobal.Permission.BLUETOOTH, NxrGlobal.Permission.BLUETOOTH_ADMIN, NxrGlobal.Permission.INTERNET, NxrGlobal.Permission.GET_TASKS, }); #endif }