/// <summary> /// Retrieves data from the current Wi-Fi network. /// </summary> /// <param name="wifiData">Reference to the struct to populate.</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if the given parameter is invalid. /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if necessary privilege is missing. /// MLResult.Result will be <c>MLResult.Code.ServiceNotAvailable</c> if the corresponding service is not available. /// MLResult.Result will be <c>MLResult.Code.ServiceError</c> if the corresponding service returned with error. /// MLResult.Result will be <c>MLResult.Code.WiFiDataStructureVersionError</c> if the version number in the given struct is not recognized. /// MLResult.Result will be <c>MLResult.Code.WiFiServiceInvalidState</c> if the Wi-Fi service is not in the right state. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// </returns> public static MLResult GetWifiData(ref MLNetworking.WifiData wifiData) { MLResult finalResult = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLNetworking.GetWifiData failed due to internal error"); try { MLNetworkingNativeBindings.WifiDataNative wifiDataInternal = MLNetworkingNativeBindings.WifiDataNative.Create(); MLResult.Code result = MLNetworkingNativeBindings.MLNetworkingGetWiFiData(ref wifiDataInternal); if (result != MLResult.Code.Ok) { MLPluginLog.ErrorFormat("MLNetworking.GetWifiData failed to get Wi-Fi data. Reason: {0}", result); wifiData = new MLNetworking.WifiData(); } else { wifiData = wifiDataInternal.Data; } finalResult = MLResult.Create(result); } catch (System.DllNotFoundException) { MLPluginLog.Error("MLNetworking API is currently available only on device."); finalResult = MLResult.Create(MLResult.Code.UnspecifiedFailure, "Dll not found"); } catch (System.EntryPointNotFoundException) { string errorMessage = string.Format("MLNetworking API symbols not found"); finalResult = MLResult.Create(MLResult.Code.UnspecifiedFailure, errorMessage); } return(finalResult); }
/// <summary> /// Retrieves if there's currently internet connection. /// </summary> /// <param name="isConnected">Reference to populate with whether or not there's internet connectivity.</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if isConnected parameter is invalid. /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if necessary privilege is missing. /// MLResult.Result will be <c>MLResult.Code.ServiceNotAvailable</c> if the corresponding service is not available. /// MLResult.Result will be <c>MLResult.Code.ServiceError </c> if the corresponding service returned with error. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error. /// </returns> public static MLResult IsInternetConnected(ref bool isConnected) { MLResult finalResult = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLNetworking.IsInternetConnected failed due to internal error"); try { isConnected = false; MLResult.Code result = MLNetworkingNativeBindings.MLNetworkingIsInternetConnected(ref isConnected); if (result != MLResult.Code.Ok) { MLPluginLog.ErrorFormat("MLNetworking.IsInternetConnected failed to check if device is connected to internet. Reason: {0}", result); isConnected = false; } finalResult = MLResult.Create(result); } catch (System.DllNotFoundException) { MLPluginLog.Error("MLNetworking API is currently available only on device."); finalResult = MLResult.Create(MLResult.Code.UnspecifiedFailure, "Dll not found"); } catch (System.EntryPointNotFoundException) { string errorMessage = string.Format("MLNetworking API symbols not found"); finalResult = MLResult.Create(MLResult.Code.UnspecifiedFailure, errorMessage); } return(finalResult); }
/// <summary> /// Gets a readable version of the result code as an ASCII string. /// </summary> /// <param name="resultCode">The MLResult that should be converted.</param> /// <returns>ASCII string containing a readable version of the result code.</returns> public static string GetResultString(MLResult.Code resultCode) { string finalResult = "MLNetworking.GetResultString failed due to internal error"; try { finalResult = Marshal.PtrToStringAnsi(MLNetworkingNativeBindings.MLNetworkingGetResultString(resultCode)); } catch (System.DllNotFoundException) { MLPluginLog.Error("MLNetworking API is currently available only on device."); finalResult = "MLNetworking API is currently available only on device."; } catch (System.EntryPointNotFoundException) { MLPluginLog.Error("MLNetworking API symbols not found"); finalResult = "MLNetworking API symbols not found"; } return(finalResult); }
/// <summary> /// Provides the string value for any MLResult.Code. /// </summary> /// <param name="resultCode">The code to convert into a string value.</param> /// <returns>The string value of the given MLResult.Code.</returns> public static string CodeToString(MLResult.Code resultCode) { string codeString = string.Empty; switch ((CodePrefix)((int)resultCode >> 16)) { case CodePrefix.MLResultGlobal: case CodePrefix.MLSnapshotResult: codeString = Marshal.PtrToStringAnsi(MagicLeapNativeBindings.MLSnapshotGetResultString(resultCode)); break; case CodePrefix.MLAudioResult: codeString = Marshal.PtrToStringAnsi(MLAudio.GetResultString(resultCode)); break; case CodePrefix.MLMediaDRMResult: case CodePrefix.MLMediaGenericResult: case CodePrefix.MLMediaPlayerResult: case CodePrefix.MLMediaResult: codeString = Marshal.PtrToStringAnsi(MLMediaPlayer.GetResultString(resultCode)); break; case CodePrefix.MLDispatchResult: codeString = Marshal.PtrToStringAnsi(MLDispatch.GetResultString(resultCode)); break; case CodePrefix.MLIdentityResult: codeString = Marshal.PtrToStringAnsi(MLIdentity.GetResultString(resultCode)); break; case CodePrefix.MLPassableWorldResult: codeString = Marshal.PtrToStringAnsi(MLPersistentCoordinateFrames.GetResultString(resultCode)); break; case CodePrefix.MLTokenAgentResult: codeString = Marshal.PtrToStringAnsi(MLTokenAgent.GetResultString(resultCode)); break; case CodePrefix.MLPrivilegesResult: codeString = Marshal.PtrToStringAnsi(MLPrivileges.GetResultString(resultCode)); break; case CodePrefix.MLContactsResult: codeString = Marshal.PtrToStringAnsi(MLContacts.GetResultString(resultCode)); break; case CodePrefix.MLLocationResult: codeString = Marshal.PtrToStringAnsi(MLLocation.GetResultString(resultCode)); break; case CodePrefix.MLNetworkingResult: codeString = Marshal.PtrToStringAnsi(MLNetworkingNativeBindings.MLNetworkingGetResultString(resultCode)); break; case CodePrefix.MLMovementResult: codeString = Marshal.PtrToStringAnsi(MLMovement.GetResultString(resultCode)); break; case CodePrefix.MLConnectionsResult: codeString = Marshal.PtrToStringAnsi(MLConnections.GetResultString(resultCode)); break; case CodePrefix.MLSecureStorageResult: codeString = Marshal.PtrToStringAnsi(MLSecureStorageNativeBindings.MLSecureStorageGetResultString(resultCode)); break; case CodePrefix.MLAppConnect: codeString = Marshal.PtrToStringAnsi(MLAppConnectNativeBindings.MLAppConnectGetResultString(resultCode)); break; case CodePrefix.MLWebRTC: codeString = Marshal.PtrToStringAnsi(MLWebRTC.NativeBindings.MLWebRTCGetResultString(resultCode)); break; case CodePrefix.MLBluetoothGattResult: codeString = Marshal.PtrToStringAnsi(MLBluetoothLE.NativeBindings.MLBluetoothGattGetResultString(resultCode)); break; default: // This will catch any unknown/invalid return values. codeString = MagicLeapNativeBindings.MLGetResultString(resultCode); break; } return(codeString); }