public int read(ref byte[] bytes) { JNIFind(); if (_instance == IntPtr.Zero) { Debug.LogError("_instance is not initialized"); return(-1); } if (_jmRead == IntPtr.Zero) { Debug.LogError("_jmRead is not initialized"); return(-1); } IntPtr arg1 = AndroidJNI.ToByteArray(bytes); int result = AndroidJNI.CallIntMethod(_instance, _jmRead, new jvalue[] { new jvalue() { l = arg1 } }); byte[] copy = AndroidJNI.FromByteArray(arg1); Array.Copy(copy, bytes, copy.Length); AndroidJNI.DeleteLocalRef(arg1); return(result); }
private int InternalRead(int length, out sbyte[] result) { IntPtr resultPtr = AndroidJNI.NewSByteArray(length); int offset = 0; int bytesLeft = length; while (bytesLeft > 0) { s_InternalReadArgs[0] = new jvalue() { l = resultPtr }; s_InternalReadArgs[1] = new jvalue() { i = offset }; s_InternalReadArgs[2] = new jvalue() { i = bytesLeft }; int bytesRead = AndroidJNI.CallIntMethod(m_FileStreamRawObject, s_InternalReadMethodId, s_InternalReadArgs); if (bytesRead <= 0) { break; } offset += bytesRead; bytesLeft -= bytesRead; } result = AndroidJNI.FromSByteArray(resultPtr); AndroidJNI.DeleteLocalRef(resultPtr); return(offset); }
public override int Read(byte[] buffer, int offset, int count) { lock (_lock) { int ret = 0; IntPtr array = IntPtr.Zero; try { array = AndroidJNI.NewByteArray(count); var method = AndroidJNIHelper.GetMethodID(inputStream.GetRawClass(), "read", "([B)I"); ret = AndroidJNI.CallIntMethod(inputStream.GetRawObject(), method, new[] { new jvalue() { l = array } }); byte[] data = AndroidJNI.FromByteArray(array); Array.Copy(data, 0, buffer, offset, ret); } finally { if (array != IntPtr.Zero) { AndroidJNI.DeleteLocalRef(array); } } return(ret); } }
private void JoinServer(HostData hostData) { #if UNITY_ANDROID AndroidJNI.CallIntMethod(); #endif Network.Connect(hostData); }
int Read(AndroidJavaObject javaObject, byte[] buffer, int offset, int count) { var args = new object[] { buffer, offset, count }; IntPtr methodID = AndroidJNIHelper.GetMethodID <int>(javaObject.GetRawClass(), "read", args, false); jvalue[] array = AndroidJNIHelper.CreateJNIArgArray(args); try { var readLen = AndroidJNI.CallIntMethod(javaObject.GetRawObject(), methodID, array); if (readLen > 0) { var temp = AndroidJNI.FromByteArray(array[0].l); Array.Copy(temp, offset, buffer, offset, readLen); } /* * for (var i = offset; i < readLen; ++i) * { * buffer[i] = AndroidJNI.GetByteArrayElement(array[0].l, i); * } */ return(readLen); } finally { AndroidJNIHelper.DeleteJNIArgArray(args, array); } }
public int getInt(string name) { #if VERBOSE_LOGGING Debug.Log(MethodBase.GetCurrentMethod().Name); #endif JNIFind(); if (_jcJsonObject == IntPtr.Zero) { Debug.LogError("_jcJsonObject is not initialized"); return(0); } if (_jmGetInt == IntPtr.Zero) { Debug.LogError("_jmGetInt is not initialized"); return(0); } IntPtr arg1 = AndroidJNI.NewStringUTF(name); int result = AndroidJNI.CallIntMethod(_instance, _jmGetInt, new jvalue[] { new jvalue() { l = arg1 } }); AndroidJNI.DeleteLocalRef(arg1); return(result); }
private void UpdateCharastricsKeys(string addr, IntPtr device) { List <BleCharastericsKeyInfo> list = null; if (this.charastericsKeyInfos.TryGetValue(addr, out list)) { return; } var blitCharaMethod = AndroidJNI.GetMethodID(this.bleDeviceCls, "blitChara", "()V"); var getKeyNumMethod = AndroidJNI.GetMethodID(this.bleDeviceCls, "getKeysNum", "()I"); var getServiceUuidFromKeysMethod = AndroidJNI.GetMethodID(this.bleDeviceCls, "getServiceUuidFromKeys", "(I)Ljava/lang/String;"); var getCharastricUuidFromKeysMethod = AndroidJNI.GetMethodID(this.bleDeviceCls, "getCharastricUuidFromKeys", "(I)Ljava/lang/String;"); // blit chara AndroidJNI.CallVoidMethod(device, blitCharaMethod, null); int num = AndroidJNI.CallIntMethod(device, getKeyNumMethod, null); if (num <= 0) { return; } list = new List <BleCharastericsKeyInfo>(num); for (int i = 0; i < num; ++i) { this.argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(i)); string serviceUuid = AndroidJNI.CallStringMethod(device, getServiceUuidFromKeysMethod, argBuilder.Build()); string charastricUuid = AndroidJNI.CallStringMethod(device, getCharastricUuidFromKeysMethod, argBuilder.Build()); var keyInfo = new BleCharastericsKeyInfo(addr, serviceUuid, charastricUuid); list.Add(keyInfo); } this.charastericsKeyInfos.Add(addr, list); }
public void UpdateScannerResult() { AndroidJNI.PushLocalFrame(32); var scanner = GetScanner(); var blitMethod = AndroidJNI.GetMethodID(this.bleScannerCls, "blit", "()V"); var getDeviceNumMethod = AndroidJNI.GetMethodID(this.bleScannerCls, "getDeviceNum", "()I"); var getDeviceAddrMethod = AndroidJNI.GetMethodID(this.bleScannerCls, "getDeviceAddr", "(I)Ljava/lang/String;"); var getDeviceNameByAddrMethod = AndroidJNI.GetMethodID(this.bleScannerCls, "getDeviceNameByAddr", "(Ljava/lang/String;)Ljava/lang/String;"); var getRssiByAddrMethod = AndroidJNI.GetMethodID(this.bleScannerCls, "getRssiByAddr", "(Ljava/lang/String;)I"); AndroidJNI.CallVoidMethod(scanner, blitMethod, null); int num = AndroidJNI.CallIntMethod(scanner, getDeviceNumMethod, null); scannedDevices.Clear(); for (int i = 0; i < num; ++i) { argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(i)); string addr = AndroidJNI.CallStringMethod(scanner, getDeviceAddrMethod, argBuilder.Build()); argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(addr)); string name = AndroidJNI.CallStringMethod(scanner, getDeviceNameByAddrMethod, argBuilder.Build()); int rssi = AndroidJNI.CallIntMethod(scanner, getRssiByAddrMethod, argBuilder.Build()); var scanDevice = new BleScannedDevice(addr, name, rssi); this.scannedDevices.Add(scanDevice); } AndroidJNI.PopLocalFrame(IntPtr.Zero); }
public byte[] ReadAllBytes() { byte[] ret = null; #if UNITY_ANDROID_NATIVE if (ByteLength > 0 && _stream != null) { var byteArray = AndroidJNI.NewByteArray(_byteLength); if (byteArray != IntPtr.Zero) { _args[0] = new jvalue() { l = byteArray }; AndroidJNI.CallIntMethod(_stream.GetRawObject(), kMethodPtr_Read, _args); ret = AndroidJNI.FromByteArray(byteArray); AndroidJNI.DeleteLocalRef(byteArray); } } #else var path = string.Format("{0}/{1}", _streamingAssetsPath, FileName); if (File.Exists(path)) { return(File.ReadAllBytes(path)); } #endif //UNITY_ANDROID_NATIVE return(ret); }
public void UpdateDisconnectedDevices() { var updateDisconnectedMethod = AndroidJNI.GetMethodID(this.bleManagerCls, "updateDisconnected", "()V"); var getDisconnectedNumMethod = AndroidJNI.GetMethodID(this.bleManagerCls, "getDisconnectedDeviceNum", "()I"); var getDisconnectedDeviceAddr = AndroidJNI.GetMethodID(this.bleManagerCls, "getDisconnectedDeviceAddr", "(I)Ljava/lang/String;"); AndroidJNI.CallVoidMethod(this.javaBleManagerObj, updateDisconnectedMethod, null); disconnectedDevices.Clear(); int num = AndroidJNI.CallIntMethod(this.javaBleManagerObj, getDisconnectedNumMethod, null); for (int i = 0; i < num; ++i) { this.argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(i)); string addr = AndroidJNI.CallStringMethod(this.javaBleManagerObj, getDisconnectedDeviceAddr, this.argBuilder.Build()); this.disconnectedDevices.Add(addr); } foreach (var addr in disconnectedDevices) { this.charastericsKeyInfos.Remove(addr); } }
public static void ReadSharedURLAndroid(FileStream fileStream) { using (var activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic <AndroidJavaObject>("currentActivity")) using (var intent = activity.Call <AndroidJavaObject>("getIntent")) using (var uri = intent.Call <AndroidJavaObject>("getData")) using (var contentResolver = activity.Call <AndroidJavaObject>("getContentResolver")) using (var inputStream = contentResolver.Call <AndroidJavaObject>("openInputStream", uri)) { byte[] buffer = new byte[1024]; var bufferPtr = AndroidJNIHelper.ConvertToJNIArray(buffer); // get the method id of InputStream.read(byte[] b, int off, int len) var readMethodId = AndroidJNIHelper.GetMethodID(inputStream.GetRawClass(), "read", "([BII)I"); jvalue[] args = new jvalue[3]; // construct arguments to pass to InputStream.read args[0].l = bufferPtr; // buffer args[1].i = 0; // offset args[2].i = buffer.Length; // length while (true) { int bytesRead = AndroidJNI.CallIntMethod(inputStream.GetRawObject(), readMethodId, args); if (bytesRead <= 0) { break; } byte[] newBuffer = AndroidJNIHelper.ConvertFromJNIArray <byte[]>(bufferPtr); fileStream.Write(newBuffer, 0, bytesRead); } fileStream.Flush(); } }
public static void GetApps() { IntPtr clas = AndroidJNI.FindClass("MakeImageCache"); clas = AndroidJNI.NewGlobalRef(clas); IntPtr funcID = AndroidJNI.GetMethodID(clas, "getApps", "()V"); AndroidJNI.CallStaticVoidMethod(clas, funcID, null); IntPtr nameID = AndroidJNI.GetMethodID(clas, "getName", "(I)Ljava/lang/String;"); nameID = AndroidJNI.NewGlobalRef(nameID); IntPtr length = AndroidJNI.GetMethodID(clas, "getTotalApps", "()I"); length = AndroidJNI.NewGlobalRef(length); int j = AndroidJNI.CallIntMethod(clas, length, null); Debug.Log("hehehe " + j); jvalue[] val = new jvalue[1]; val[0] = new jvalue(); Debug.Log("loading apps ..."); for (int i = 0; i < j; i++) { val[0].i = i; Debug.Log("hehehe"); Debug.Log(AndroidJNI.CallStaticStringMethod(clas, nameID, val)); } Debug.Log("loaded apps!"); }
private static void ReadSharedURL(Stream outputStream) { using (var activity = AndroidShare.GetCurrentActivity()) using (var intent = activity.Call <AndroidJavaObject>("getIntent")) using (var uri = intent.Call <AndroidJavaObject>("getData")) using (var inputStream = GetInputStreamForURI(uri, activity)) { byte[] buffer = new byte[8192]; var bufferPtr = AndroidJNIHelper.ConvertToJNIArray(buffer); // get the method id of InputStream.read(byte[] b, int off, int len) var readMethodId = AndroidJNIHelper.GetMethodID(inputStream.GetRawClass(), "read", "([BII)I"); jvalue[] args = new jvalue[3]; // construct arguments to pass to InputStream.read args[0].l = bufferPtr; // buffer args[1].i = 0; // offset args[2].i = buffer.Length; // length while (true) { int bytesRead = AndroidJNI.CallIntMethod(inputStream.GetRawObject(), readMethodId, args); if (bytesRead <= 0) { break; } byte[] newBuffer = AndroidJNIHelper.ConvertFromJNIArray <byte[]>(bufferPtr); outputStream.Write(newBuffer, 0, bytesRead); } outputStream.Flush(); } }
public void InputStreamTest() { if (Application.platform == RuntimePlatform.Android) { string strName = "audiotest/takeleap/com/playsound/PlaySoundExternal"; IntPtr localRef = AndroidJNI.FindClass(strName); IntPtr unityClass = AndroidJNI.FindClass("com/unity3d/player/UnityPlayer"); IntPtr inputStreamClass = AndroidJNI.FindClass("java/io/InputStream"); if (localRef != IntPtr.Zero) { print("NOT NULL"); IntPtr instancePtr = AndroidJNI.CallStaticObjectMethod(localRef, AndroidJNI.GetStaticMethodID(localRef, "instance", "()Laudiotest/takeleap/com/playsound/PlaySoundExternal;"), new jvalue[] { }); if (instancePtr != null) { print("Instance PTR NOT NULL BRO"); } else { print("Instance PTR NULL BRO"); } print(AndroidJNI.CallIntMethod(instancePtr, AndroidJNI.GetMethodID(localRef, "TestPluginNonStatic", "()I"), new jvalue[] { })); // IntPtr currentActivityPtr = AndroidJNI.GetStaticObjectField(unityClass, AndroidJNI.GetStaticFieldID(unityClass, "currentActivity", "Landroid/app/Activity;")); // IntPtr inputStreamPtr = AndroidJNI.CallObjectMethod(instancePtr, AndroidJNI.GetMethodID(localRef, "GetInputStream", // "(Landroid/content/Context;)Ljava/io/InputStream;"), // AndroidJNIHelper.CreateJNIArgArray(new object[] { currentActivityPtr })); // if (inputStreamPtr != null) // { // print("INPUT STREAM NOT NULL"); // byte[] buffer = new byte[300]; // jvalue[] args = AndroidJNIHelper.CreateJNIArgArray(new object[] { buffer }); // int numRead = AndroidJNI.CallIntMethod(inputStreamPtr, AndroidJNI.GetMethodID(inputStreamClass, "read", "([B)I"), args); // print(numRead); // } // else // { // print("INPUT STREAM IS NULL"); // } print("END"); } else { print("IS NULL"); } } }
public T InvokeCall <T>(string name, string sig, params object[] args) { T local; Type type = typeof(T); IntPtr methodID = AndroidJNI.GetMethodID(this.RawClass, name, sig); if (methodID == IntPtr.Zero) { Debug.LogError("Cannot get method for " + name); throw new Exception("Cannot get method for " + name); } jvalue[] jvalueArray = ConstructArgArray(args); try { if (type == typeof(bool)) { return((T)AndroidJNI.CallBooleanMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(string)) { return((T)AndroidJNI.CallStringMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(int)) { return((T)AndroidJNI.CallIntMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(float)) { return((T)AndroidJNI.CallFloatMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(double)) { return((T)AndroidJNI.CallDoubleMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(byte)) { return((T)AndroidJNI.CallByteMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(char)) { return((T)AndroidJNI.CallCharMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(long)) { return((T)AndroidJNI.CallLongMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(short)) { return((T)AndroidJNI.CallShortMethod(this.raw, methodID, jvalueArray)); } local = this.InvokeObjectCall <T>(name, sig, args); } finally { AndroidJNIHelper.DeleteJNIArgArray(args, jvalueArray); } return(local); }
public static int CallIntMethod(IntPtr obj, IntPtr methodId, jvalue[] args) { try { return(AndroidJNI.CallIntMethod(obj, methodId, args)); } finally { CheckException(); } }
public T InvokeCall <T>(string name, string sig, params object[] args) { System.Type type = typeof(T); IntPtr objectClass = AndroidJNI.GetObjectClass(this.raw); IntPtr methodID = AndroidJNI.GetMethodID(objectClass, name, sig); jvalue[] jvalueArray = ConstructArgArray(args); if (objectClass == IntPtr.Zero) { Debug.LogError("Cannot get rawClass object!"); throw new Exception("Cannot get rawClass object"); } if (methodID == IntPtr.Zero) { Debug.LogError("Cannot get method for " + name); throw new Exception("Cannot get method for " + name); } if (type == typeof(bool)) { return((T)AndroidJNI.CallBooleanMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(string)) { return((T)AndroidJNI.CallStringMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(int)) { return((T)AndroidJNI.CallIntMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(float)) { return((T)AndroidJNI.CallFloatMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(double)) { return((T)AndroidJNI.CallDoubleMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(byte)) { return((T)AndroidJNI.CallByteMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(char)) { return((T)AndroidJNI.CallCharMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(long)) { return((T)AndroidJNI.CallLongMethod(this.raw, methodID, jvalueArray)); } if (type == typeof(short)) { return((T)AndroidJNI.CallShortMethod(this.raw, methodID, jvalueArray)); } return(this.InvokeObjectCall <T>(name, sig, args)); }
public T InvokeCall <T>(string name, string sig, params object[] args) { Type t = typeof(T); IntPtr method = AndroidJNI.GetMethodID(RawClass, name, sig); jvalue[] jArgs = ConstructArgArray(args); if (method == IntPtr.Zero) { Debug.LogError("Cannot get method for " + name); throw new Exception("Cannot get method for " + name); } if (t == typeof(bool)) { return((T)(object)AndroidJNI.CallBooleanMethod(raw, method, jArgs)); } else if (t == typeof(string)) { return((T)(object)AndroidJNI.CallStringMethod(raw, method, jArgs)); } else if (t == typeof(int)) { return((T)(object)AndroidJNI.CallIntMethod(raw, method, jArgs)); } else if (t == typeof(float)) { return((T)(object)AndroidJNI.CallFloatMethod(raw, method, jArgs)); } else if (t == typeof(double)) { return((T)(object)AndroidJNI.CallDoubleMethod(raw, method, jArgs)); } else if (t == typeof(byte)) { return((T)(object)AndroidJNI.CallByteMethod(raw, method, jArgs)); } else if (t == typeof(char)) { return((T)(object)AndroidJNI.CallCharMethod(raw, method, jArgs)); } else if (t == typeof(long)) { return((T)(object)AndroidJNI.CallLongMethod(raw, method, jArgs)); } else if (t == typeof(short)) { return((T)(object)AndroidJNI.CallShortMethod(raw, method, jArgs)); } else { return(InvokeObjectCall <T>(name, sig, args)); } }
public int getPayCode() { CxxJavaObject.callJavaStart(); IntPtr jthiz = getLocalJavaObject(); IntPtr jclazz = CxxJavaObject.getJavaClass(jthiz); IntPtr jmethod = CxxJavaObject.getJavaMethodID(jclazz, "getPayCode", "()I"); int jret = AndroidJNI.CallIntMethod(jthiz, jmethod, CxxJavaObject.createJavaParam((object)null)); CxxJavaObject.callJavaEnd(); return(jret); }
/// <summary> /// 从Asset中拷贝lua文件 /// </summary> /// <param name="path">目录路径.</param> private void copyLuaFileFromAsset(string path) { AndroidJavaObject currentActivity = getCurrentActivity(); AndroidJavaObject assetManager = currentActivity.Call <AndroidJavaObject> ("getAssets", new object[0]); string[] subpaths = assetManager.Call <string[]> ("list", path); if (subpaths.Length > 0) { //当前path为目录 foreach (string subpath in subpaths) { copyLuaFileFromAsset(string.Format("{0}{1}/", path, subpath)); } } else { //当前path为文件 string fileName = path.Substring(0, path.Length - 1); if (fileName.ToLower().EndsWith(".lua")) { //为lua文件,则进行拷贝 string destFilePath = getLuaCacheFilePath(fileName); AndroidJavaObject inputStream = assetManager.Call <AndroidJavaObject>("open", fileName); using (MemoryStream ms = new MemoryStream()) { try { IntPtr buffer = AndroidJNI.NewByteArray(1024); jvalue[] args = new jvalue[1]; args[0].l = buffer; IntPtr readMethodId = AndroidJNIHelper.GetMethodID(inputStream.GetRawClass(), "read", "([B)I"); int hasRead = 0; while ((hasRead = AndroidJNI.CallIntMethod(inputStream.GetRawObject(), readMethodId, args)) != -1) { byte[] byteArray = AndroidJNIHelper.ConvertFromJNIArray <byte[]>(buffer); ms.Write(byteArray, 0, hasRead); } ms.Seek(0, SeekOrigin.Begin); byte[] bytes = new byte[ms.Length]; ms.Read(bytes, 0, bytes.Length); File.WriteAllBytes(destFilePath, bytes); } finally { ms.Close(); } } } } }
public int size() { if (_instance == IntPtr.Zero) { Debug.LogError("_instance is not initialized"); return(0); } int result = AndroidJNI.CallIntMethod(_instance, _jmSize, new jvalue[0]); Debug.Log(string.Format("ByteArrayOutputStream.size() == {0}", result)); return(result); }
public byte[] readAllBytes() { var availbleBytes = getFileSize(); var byteArray = AndroidJNI.NewByteArray(availbleBytes); int readCout = AndroidJNI.CallIntMethod(_stream.GetRawObject(), METHOD_read, new[] { new jvalue() { l = byteArray } }); var bytes = AndroidJNI.FromByteArray(byteArray); AndroidJNI.DeleteGlobalRef(byteArray); return(bytes); }
public T InvokeCall <T>(string name, string sig, params object[] args) { Type t = typeof(T); IntPtr rawClass = AndroidJNI.GetObjectClass(raw); IntPtr method = AndroidJNI.GetMethodID(rawClass, name, sig); jvalue[] jArgs = ConstructArgArray(args); if (t == typeof(bool)) { return((T)(object)AndroidJNI.CallBooleanMethod(raw, method, jArgs)); } else if (t == typeof(string)) { return((T)(object)AndroidJNI.CallStringMethod(raw, method, jArgs)); } else if (t == typeof(int)) { return((T)(object)AndroidJNI.CallIntMethod(raw, method, jArgs)); } else if (t == typeof(float)) { return((T)(object)AndroidJNI.CallFloatMethod(raw, method, jArgs)); } else if (t == typeof(double)) { return((T)(object)AndroidJNI.CallDoubleMethod(raw, method, jArgs)); } else if (t == typeof(byte)) { return((T)(object)AndroidJNI.CallByteMethod(raw, method, jArgs)); } else if (t == typeof(char)) { return((T)(object)AndroidJNI.CallCharMethod(raw, method, jArgs)); } else if (t == typeof(long)) { return((T)(object)AndroidJNI.CallLongMethod(raw, method, jArgs)); } else if (t == typeof(short)) { return((T)(object)AndroidJNI.CallShortMethod(raw, method, jArgs)); } else { return(InvokeObjectCall <T>(name, sig, args)); } }
private static byte[] LoadFileFromStreamingAssets(string file) { #if UNITY_EDITOR || UNITY_STANDALONE string assembly = Path.Combine(Application.streamingAssetsPath, file); if (File.Exists(assembly)) { var bytes = File.ReadAllBytes(assembly); return(bytes); } #elif UNITY_ANDROID AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject androidJavaActivity = null; AndroidJavaObject assetManager = null; AndroidJavaObject inputStream = null; if (androidJavaClass != null) { androidJavaActivity = androidJavaClass.GetStatic <AndroidJavaObject>("currentActivity"); } if (androidJavaActivity != null) { assetManager = androidJavaActivity.Call <AndroidJavaObject>("getAssets"); } if (assetManager != null) { inputStream = assetManager.Call <AndroidJavaObject>("open", file); } if (inputStream != null) { int available = inputStream.Call <int>("available"); System.IntPtr buffer = AndroidJNI.NewByteArray(available); System.IntPtr javaClass = AndroidJNI.FindClass("java/io/InputStream"); System.IntPtr javaMethodID = AndroidJNIHelper.GetMethodID(javaClass, "read", "([B)I"); int read = AndroidJNI.CallIntMethod(inputStream.GetRawObject(), javaMethodID, new[] { new jvalue() { l = buffer } }); byte[] bytes = AndroidJNI.FromByteArray(buffer); AndroidJNI.DeleteLocalRef(buffer); inputStream.Call("close"); inputStream.Dispose(); return(bytes); } #endif return(null); }
private int InternalRead(int length, out byte[] result) { #if UNITY_2019_2_OR_NEWER #pragma warning disable CS0618 #endif IntPtr resultPtr = AndroidJNI.NewByteArray(length); #if UNITY_2019_2_OR_NEWER #pragma warning restore CS0618 #endif int offset = 0; int bytesLeft = length; while (bytesLeft > 0) { s_InternalReadArgs[0] = new jvalue() { l = resultPtr }; s_InternalReadArgs[1] = new jvalue() { i = offset }; s_InternalReadArgs[2] = new jvalue() { i = bytesLeft }; int bytesRead = AndroidJNI.CallIntMethod(m_FileStreamRawObject, s_InternalReadMethodId, s_InternalReadArgs); if (bytesRead <= 0) { break; } offset += bytesRead; bytesLeft -= bytesRead; } #if UNITY_2019_2_OR_NEWER #pragma warning disable CS0618 #endif result = AndroidJNI.FromByteArray(resultPtr); #if UNITY_2019_2_OR_NEWER #pragma warning restore CS0618 #endif AndroidJNI.DeleteLocalRef(resultPtr); return(offset); }
public int GetSkinTempLevel() { int currentTempLevel = -1; try { currentTempLevel = AndroidJNI.CallIntMethod(s_GameSDKRawObjectID, s_GetSkinTempLevelID, s_NoArgs); if (AndroidJNI.ExceptionOccurred() != IntPtr.Zero) { AndroidJNI.ExceptionDescribe(); AndroidJNI.ExceptionClear(); } } catch (Exception) { GameSDKLog.Debug("[Exception] GameSDK.getSkinTempLevel() failed!"); } return currentTempLevel; }
public int Read(byte[] buffer, int index, int numOfBytesToRead) { #if UNITY_ANDROID _readMethodParameters[1].i = numOfBytesToRead; var numOfBytesRead = AndroidJNI.CallIntMethod(_port.GetRawObject(), _readMethodId, _readMethodParameters); byte[] tempBuffer = AndroidJNIHelper.ConvertFromJNIArray <byte[]>(_javaReadBuffer); Buffer.BlockCopy(tempBuffer, 0, buffer, index, numOfBytesRead); return(numOfBytesRead); #else // Assume compiling on WIN32 or UNITY_STANDALONE_WIN. return(_port.Read(buffer, index, numOfBytesToRead)); #endif }
public T InvokeCall <T>(string name, string sig, params object[] args) { Type type = typeof(T); IntPtr methodId = AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(this.raw), name, sig); jvalue[] jvalueArray = JavaObjWrapper.ConstructArgArray(args); if ((object)type == (object)typeof(bool)) { return((T)(ValueType)AndroidJNI.CallBooleanMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(string)) { return((T)AndroidJNI.CallStringMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(int)) { return((T)(ValueType)AndroidJNI.CallIntMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(float)) { return((T)(ValueType)AndroidJNI.CallFloatMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(double)) { return((T)(ValueType)AndroidJNI.CallDoubleMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(byte)) { return((T)(ValueType)AndroidJNI.CallByteMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(char)) { return((T)(ValueType)AndroidJNI.CallCharMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(long)) { return((T)(ValueType)AndroidJNI.CallLongMethod(this.raw, methodId, jvalueArray)); } if ((object)type == (object)typeof(short)) { return((T)(ValueType)AndroidJNI.CallShortMethod(this.raw, methodId, jvalueArray)); } return(this.InvokeObjectCall <T>(name, sig, args)); }
public int getRatingCount() { #if VERBOSE_LOGGING Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name)); #endif JNIFind(); if (_instance == IntPtr.Zero) { Debug.LogError("_instance is not initialized"); return(0); } if (_jmGetRatingCount == IntPtr.Zero) { Debug.LogError("_jmGetRatingCount is not initialized"); return(0); } return(AndroidJNI.CallIntMethod(_instance, _jmGetRatingCount, new jvalue[0] { })); }
public void UpdateConnectedDevices() { this.readDatas.Clear(); AndroidJNI.PushLocalFrame(32); var getConnectedDeviceNumMethod = AndroidJNI.GetMethodID(bleManagerCls, "getConnectedDeviceNum", "()I"); var getConnectedDeviceMethod = AndroidJNI.GetMethodID(bleManagerCls, "getConnectedDevice", "(I)Lcom/toio/ble/BleDeviceObj;"); int num = AndroidJNI.CallIntMethod(javaBleManagerObj, getConnectedDeviceNumMethod, null); for (int i = 0; i < num; ++i) { AndroidJNI.PushLocalFrame(32); this.argBuilder.Clear().Append(ArgJvalueBuilder.GenerateJvalue(i)); var device = AndroidJNI.CallObjectMethod(this.javaBleManagerObj, getConnectedDeviceMethod, argBuilder.Build()); this.UpdateBleDevice(device); AndroidJNI.PopLocalFrame(IntPtr.Zero); } AndroidJNI.PopLocalFrame(IntPtr.Zero); }