public static int GetAvailableViews(string zone_id) { jvalue[] args = new jvalue[1]; args[0].l = AndroidJNI.NewStringUTF(zone_id); return(AndroidJNI.CallStaticIntMethod(class_UnityADC, method_getAvailableViews, args)); }
private static int BurstlyCurrencyWrapper_getBalance(string currency) { jvalue[] args = new jvalue[1]; args[0].l = AndroidJNI.NewStringUTF(currency); return(AndroidJNI.CallStaticIntMethod(BurstlyPluginClass, methodID_getBalance, args)); }
private static void BurstlyCurrencyWrapper_setCallbackGameObjectName(string callbackGameObjectName) { jvalue[] args = new jvalue[1]; args[0].l = AndroidJNI.NewStringUTF(callbackGameObjectName); AndroidJNI.CallStaticVoidMethod(BurstlyPluginClass, methodID_setCallbackGameObjectName, args); }
private static bool isInstanceOf(AndroidJavaObject jniItem, string classJniStr) { System.IntPtr cls = AndroidJNI.FindClass(classJniStr); return(AndroidJNI.IsInstanceOf(jniItem.GetRawObject(), cls)); }
static OuyaController() { try { { string strName = "tv/ouya/console/api/OuyaController"; _jcOuyaController = AndroidJNI.FindClass(strName); if (_jcOuyaController != IntPtr.Zero) { Debug.Log(string.Format("Found {0} class", strName)); } else { Debug.LogError(string.Format("Failed to find {0} class", strName)); return; } } { string strMethod = "getControllerByPlayer"; _jmGetControllerByPlayer = AndroidJNI.GetStaticMethodID(_jcOuyaController, strMethod, "(I)Ltv/ouya/console/api/OuyaController;"); if (_jmGetControllerByPlayer != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getDeviceName"; _jmGetDeviceName = AndroidJNI.GetMethodID(_jcOuyaController, strMethod, "()Ljava/lang/String;"); if (_jmGetDeviceName != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getButtonData"; _jmGetButtonData = AndroidJNI.GetStaticMethodID(_jcOuyaController, strMethod, "(I)Ltv/ouya/console/api/OuyaController$ButtonData;"); if (_jmGetButtonData != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "showCursor"; _jmShowCursor = AndroidJNI.GetStaticMethodID(_jcOuyaController, strMethod, "(Z)V"); if (_jmShowCursor != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } } catch (System.Exception) { Debug.LogError("Exception finding AsyncCppOuyaFetchGamerUUID class"); } }
public void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With") { AndroidJNI.AttachCurrentThread(); sharingJavaClass.CallStatic(ShareTextMethodName, shareText, showShareDialogBox, shareDialogBoxText); }
public static void AttachCurrentThread() { AndroidJNI.AttachCurrentThread(); }
public static void StopIabServiceInBg() { AndroidJNI.PushLocalFrame(100); jniStoreController.Call("stopIabServiceInBg"); AndroidJNI.PopLocalFrame(IntPtr.Zero); }
private static void JNIFind() { try { { string strMethod = "getJSONObject"; _jmGetJsonObject = AndroidJNI.GetMethodID(_jcJsonArray, strMethod, "(I)Lorg/json/JSONObject;"); if (_jmGetJsonObject != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getInt"; _jmGetInt = AndroidJNI.GetMethodID(_jcJsonArray, strMethod, "(I)I"); if (_jmGetInt != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getString"; _jmGetString = AndroidJNI.GetMethodID(_jcJsonArray, strMethod, "(I)Ljava/lang/String;"); if (_jmGetString != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "length"; _jmLength = AndroidJNI.GetMethodID(_jcJsonArray, strMethod, "()I"); if (_jmLength != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } } catch (System.Exception ex) { Debug.LogError(string.Format("Exception loading JNI - {0}", ex)); } }
public static List <OuyaModScreenshot> getOuyaModScreenshotList(IntPtr list) { #if VERBOSE_LOGGING Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name)); #endif JNIFind(); if (_jcOuyaUnityPlugin == IntPtr.Zero) { Debug.LogError("_jcOuyaUnityPlugin is not initialized"); return(null); } if (_jmGetOuyaModScreenshotArray == IntPtr.Zero) { Debug.LogError("_jmGetOuyaModScreenshotArray is not initialized"); return(null); } IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetOuyaModScreenshotArray, new jvalue[] { new jvalue() { l = list } }); if (result == IntPtr.Zero) { Debug.LogError("_jmGetOuyaModScreenshotArray returned null"); return(null); } List <OuyaModScreenshot> items = new List <OuyaModScreenshot>(); #if VERBOSE_LOGGING Debug.Log("Invoking AndroidJNI.FromObjectArray..."); #endif IntPtr[] resultArray = AndroidJNI.FromObjectArray(result); AndroidJNI.DeleteLocalRef(result); #if VERBOSE_LOGGING Debug.Log("Invoked AndroidJNI.FromObjectArray."); #endif foreach (IntPtr ptr in resultArray) { #if VERBOSE_LOGGING Debug.Log("Found Bitmap making Global Ref..."); #endif IntPtr globalRef = AndroidJNI.NewGlobalRef(ptr); AndroidJNI.DeleteLocalRef(ptr); #if VERBOSE_LOGGING Debug.Log("Made global ref for Bitmap."); #endif OuyaModScreenshot item = new OuyaModScreenshot(globalRef); #if VERBOSE_LOGGING Debug.Log("Deleting old local ref..."); #endif items.Add(item); } #if VERBOSE_LOGGING Debug.Log("Deleting OuyaModScreenshot list reference..."); #endif return(items); }
private static void JNIFind() { try { { string strMethod = "<init>"; _jmConstructor = AndroidJNI.GetMethodID(_jcOuyaUnityPlugin, strMethod, "(Landroid/app/Activity;)V"); if (_jmConstructor != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "initOuyaPlugin"; _jmInitOuyaPlugin = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;)V"); if (_jmInitOuyaPlugin != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getGameData"; _jmGetGameData = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;)Ljava/lang/String;"); if (_jmGetGameData != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "putGameData"; _jmPutGameData = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;Ljava/lang/String;)V"); if (_jmPutGameData != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "requestGamerInfo"; _jmRequestGamerInfo = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()V"); if (_jmRequestGamerInfo != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "requestProducts"; _jmRequestProducts = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;)V"); if (_jmRequestProducts != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "requestPurchase"; _jmRequestPurchase = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;)V"); if (_jmRequestPurchase != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "requestReceipts"; _jmRequestReceipts = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()V"); if (_jmRequestReceipts != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "isRunningOnOUYASupportedHardware"; _jmIsRunningOnOUYASupportedHardware = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()Z"); if (_jmIsRunningOnOUYASupportedHardware != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "setSafeArea"; _jmSetSafeArea = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(F)V"); if (_jmSetSafeArea != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "clearFocus"; _jmClearFocus = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()V"); if (_jmClearFocus != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getOuyaContent"; _jmGetOuyaContent = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()Ltv/ouya/console/api/content/OuyaContent;"); if (_jmGetOuyaContent != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "saveOuyaMod"; _jmSaveOuyaMod = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ltv/ouya/console/api/content/OuyaMod;Ltv/ouya/console/api/content/OuyaMod$Editor;)V"); if (_jmSaveOuyaMod != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getOuyaContentInstalled"; _jmGetOuyaContentInstalled = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()V"); if (_jmGetOuyaContentInstalled != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getOuyaContentInstalledResults"; _jmGetOuyaContentInstalledResults = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()[Ltv/ouya/console/api/content/OuyaMod;"); if (_jmGetOuyaContentInstalledResults != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getOuyaContentPublished"; _jmGetOuyaContentPublished = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;)V"); if (_jmGetOuyaContentPublished != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getOuyaContentPublishedResults"; _jmGetOuyaContentPublishedResults = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()[Ltv/ouya/console/api/content/OuyaMod;"); if (_jmGetOuyaContentPublishedResults != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "contentDelete"; _jmContentDelete = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ltv/ouya/console/api/content/OuyaMod;)V"); if (_jmContentDelete != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "contentDownload"; _jmContentDownload = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ltv/ouya/console/api/content/OuyaMod;)V"); if (_jmContentDownload != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "contentPublish"; _jmContentPublish = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ltv/ouya/console/api/content/OuyaMod;)V"); if (_jmContentPublish != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "contentUnpublish"; _jmContentUnpublish = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ltv/ouya/console/api/content/OuyaMod;)V"); if (_jmContentUnpublish != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getFloat"; _jmGetFloat = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/Float;)F"); if (_jmGetFloat != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getBitmapArray"; _jmGetBitmapArray = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/util/List;)[Landroid/graphics/Bitmap;"); if (_jmGetBitmapArray != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getOuyaModScreenshotArray"; _jmGetOuyaModScreenshotArray = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/util/List;)[Ltv/ouya/console/api/content/OuyaModScreenshot;"); if (_jmGetOuyaModScreenshotArray != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getStringArray"; _jmGetStringArray = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/util/List;)[Ljava/lang/String;"); if (_jmGetStringArray != IntPtr.Zero) { #if VERBOSE_LOGGING Debug.Log(string.Format("Found {0} method", strMethod)); #endif } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } } catch (System.Exception ex) { Debug.LogError(string.Format("Exception loading JNI - {0}", ex)); } }
/// <summary> /// Creates a new instance of the given class by calling the /// no-arg constructor. /// </summary> /// <param name="clazzName">Clazz name.</param> public JavaObjWrapper(string clazzName) { this.raw = AndroidJNI.AllocObject(AndroidJNI.FindClass(clazzName)); }
/// <summary> /// An internal method used to vibrate on a pattern/amplitude model using a secondary thread /// If you use that, you should call MMNVAndroid.ClearThreads() on exit (where exactly depends on your game, but OnDisable should cover most cases) /// </summary> /// <param name="threadData"></param> private static void AndroidVibrateThread(MMNVAndroidVibrateThreadData threadData) { AndroidJNI.AttachCurrentThread(); AndroidVibrateNoThread(threadData.Pattern, threadData.Amplitudes, threadData.Repeat); AndroidJNI.DetachCurrentThread(); }
public static void AddNativeType(List <IntPtr> nativeTypes) { nativeTypes.Add(AndroidJNI.FindClass("com/microsoft/appcenter/distribute/Distribute")); }
/// <summary> /// Stops in-app billing service in background. /// </summary> protected override void _stopIabServiceInBg() { AndroidJNI.PushLocalFrame(100); jniStoreController.Call("stopIabServiceInBg"); AndroidJNI.PopLocalFrame(IntPtr.Zero); }
public void CommitSamples(float[] sampleBuffer, long timestamp) { AndroidJNI.AttachCurrentThread(); recorder.Call(@"encodeSamples", sampleBuffer, timestamp); }
public AndroidUnityNativeSharingAdapter() { AndroidJNI.AttachCurrentThread(); sharingJavaClass = new AndroidJavaClass(AndroidClass); }
public static void AddNativeType(List <IntPtr> nativeTypes) { nativeTypes.Add(AndroidJNI.FindClass("com/microsoft/appcenter/push/Push")); }
public static void OnEvent(string actionId, Dictionary <string, object> parameters) { if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor) { if (parameters != null && parameters.Count > 0 && parameters.Count <= 10) { #if UNITY_IOS int count = parameters.Count; string [] keys = new string[count]; string [] stringValues = new string[count]; double [] numberValues = new double[count]; int index = 0; foreach (KeyValuePair <string, object> kvp in parameters) { if (kvp.Value is string) { keys[index] = kvp.Key; stringValues[index] = (string)kvp.Value; } else { try { double tmp = System.Convert.ToDouble(kvp.Value); numberValues[index] = tmp; keys[index] = kvp.Key; } catch (System.Exception) { count--; continue; } } index++; } _tdgaOnEvent(actionId, keys, stringValues, numberValues, count); #elif UNITY_ANDROID int count = parameters.Count; AndroidJavaObject map = new AndroidJavaObject("java.util.HashMap", count); IntPtr method_Put = AndroidJNIHelper.GetMethodID(map.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] args = new object[2]; foreach (KeyValuePair <string, object> kvp in parameters) { args[0] = new AndroidJavaObject("java.lang.String", kvp.Key); if (typeof(System.String).IsInstanceOfType(kvp.Value)) { args[1] = new AndroidJavaObject("java.lang.String", kvp.Value); } else { args[1] = new AndroidJavaObject("java.lang.Double", "" + kvp.Value); } AndroidJNI.CallObjectMethod(map.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } if (agent != null) { agent.CallStatic("onEvent", actionId, map); } #elif UNITY_WP8 TalkingDataGAWP.TalkingDataGA.onEvent(actionId, parameters); #endif } } }
private AndroidJavaObject convertToJavaHashMap(Dictionary <string, object> configD) { AndroidJavaObject config_Hashmap = new AndroidJavaObject("java.util.HashMap"); if (configD != null) { Dictionary <string, object> configDict = (from kv in configD where kv.Value != null select kv).ToDictionary(kv => kv.Key, kv => kv.Value); IntPtr method_Put = AndroidJNIHelper.GetMethodID(config_Hashmap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] args = new object[2]; args[0] = args[1] = null; foreach (KeyValuePair <string, object> kvp in configDict) { using (AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key)) { args[0] = k; if (kvp.Value != null && kvp.Value.Equals("yes") || kvp.Value.Equals("no")) { string value = kvp.Value.Equals("yes") ? "true" : "false"; args[1] = new AndroidJavaObject("java.lang.Boolean", value); } else if (kvp.Value != null) { if (kvp.Value.GetType().ToString() == "System.String") { args[1] = new AndroidJavaObject("java.lang.String", kvp.Value); } else if (kvp.Value.GetType().ToString() == "System.String[]") { string[] tagsArray = (string[])kvp.Value; AndroidJavaObject tags_ArrayList = new AndroidJavaObject("java.util.ArrayList"); IntPtr method_add = AndroidJNIHelper.GetMethodID(tags_ArrayList.GetRawClass(), "add", "(Ljava/lang/String;)Z"); object[] tags_args = new object[1]; foreach (string tag in tagsArray) { if (tag != null) { tags_args[0] = new AndroidJavaObject("java.lang.String", tag); AndroidJNI.CallBooleanMethod(tags_ArrayList.GetRawObject(), method_add, AndroidJNIHelper.CreateJNIArgArray(tags_args)); } } args[1] = new AndroidJavaObject("java.util.ArrayList", tags_ArrayList); } else { if (kvp.Key == HelpshiftSdk.HSCUSTOMMETADATAKEY) { Dictionary <string, object> metaMap = (Dictionary <string, object>)kvp.Value; AndroidJavaObject meta_Hashmap = new AndroidJavaObject("java.util.HashMap"); IntPtr method_MetaPut = AndroidJNIHelper.GetMethodID(meta_Hashmap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] meta_args = new object[2]; meta_args[0] = meta_args[1] = null; foreach (KeyValuePair <string, object> metaKvp in metaMap) { meta_args[0] = new AndroidJavaObject("java.lang.String", metaKvp.Key); if (metaKvp.Value.GetType().ToString() == "System.String") { meta_args[1] = new AndroidJavaObject("java.lang.String", metaKvp.Value); } else if (metaKvp.Value.GetType().ToString() == "System.Int32") { meta_args[1] = new AndroidJavaObject("java.lang.Integer", metaKvp.Value); } else if (metaKvp.Value.GetType().ToString() == "System.Double") { meta_args[1] = new AndroidJavaObject("java.lang.Double", metaKvp.Value); } else if (metaKvp.Key == HelpshiftSdk.HSTAGSKEY && metaKvp.Value.GetType().ToString() == "System.String[]") { string[] tagsArray = (string[])metaKvp.Value; AndroidJavaObject tags_ArrayList = new AndroidJavaObject("java.util.ArrayList"); IntPtr method_add = AndroidJNIHelper.GetMethodID(tags_ArrayList.GetRawClass(), "add", "(Ljava/lang/String;)Z"); object[] tags_args = new object[1]; foreach (string tag in tagsArray) { if (tag != null) { tags_args[0] = new AndroidJavaObject("java.lang.String", tag); AndroidJNI.CallBooleanMethod(tags_ArrayList.GetRawObject(), method_add, AndroidJNIHelper.CreateJNIArgArray(tags_args)); } } meta_args[1] = new AndroidJavaObject("java.util.ArrayList", tags_ArrayList); } if (meta_args[1] != null) { AndroidJNI.CallObjectMethod(meta_Hashmap.GetRawObject(), method_MetaPut, AndroidJNIHelper.CreateJNIArgArray(meta_args)); } } args[1] = new AndroidJavaObject("java.util.HashMap", meta_Hashmap); } if (kvp.Key == HelpshiftSdk.HSTAGSMATCHINGKEY) { Dictionary <string, object> tagsMatchingMap = (Dictionary <string, object>)kvp.Value; AndroidJavaObject tagsMatching_Hashmap = new AndroidJavaObject("java.util.HashMap"); IntPtr method_MetaPut = AndroidJNIHelper.GetMethodID(tagsMatching_Hashmap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] tagsMatching_args = new object[2]; tagsMatching_args[0] = tagsMatching_args[1] = null; foreach (KeyValuePair <string, object> tagsMatchKvp in tagsMatchingMap) { tagsMatching_args[0] = new AndroidJavaObject("java.lang.String", tagsMatchKvp.Key); if (tagsMatchKvp.Key == "operator" && tagsMatchKvp.Value.GetType().ToString() == "System.String") { tagsMatching_args[1] = new AndroidJavaObject("java.lang.String", tagsMatchKvp.Value); } else if (tagsMatchKvp.Key == "tags" && tagsMatchKvp.Value.GetType().ToString() == "System.String[]") { string[] tagsArray = (string[])tagsMatchKvp.Value; AndroidJavaObject tags_ArrayList = new AndroidJavaObject("java.util.ArrayList"); IntPtr method_add = AndroidJNIHelper.GetMethodID(tags_ArrayList.GetRawClass(), "add", "(Ljava/lang/String;)Z"); object[] tags_args = new object[1]; foreach (string tag in tagsArray) { if (tag != null) { tags_args[0] = new AndroidJavaObject("java.lang.String", tag); AndroidJNI.CallBooleanMethod(tags_ArrayList.GetRawObject(), method_add, AndroidJNIHelper.CreateJNIArgArray(tags_args)); } } tagsMatching_args[1] = new AndroidJavaObject("java.util.ArrayList", tags_ArrayList); } if (tagsMatching_args[1] != null) { AndroidJNI.CallObjectMethod(tagsMatching_Hashmap.GetRawObject(), method_MetaPut, AndroidJNIHelper.CreateJNIArgArray(tagsMatching_args)); } } args[1] = new AndroidJavaObject("java.util.HashMap", tagsMatching_Hashmap); } } } if (args[1] != null) { AndroidJNI.CallObjectMethod(config_Hashmap.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } } } } return(config_Hashmap); }
public static void DetachCurrentThread() { AndroidJNI.DetachCurrentThread(); }
public void OnStop() { AndroidJNI.DeleteGlobalRef(javaBuf); }
/// <summary> /// 上传文件 /// </summary> /// <param name="fileParams">文件参数.</param> /// <param name="parameters">请求参数.</param> /// <param name="resultHandler">返回回调.</param> /// <param name="faultHandler">失败回调.</param> /// <param name="progressHandler">进度回调</param> public void upload( Dictionary <string, HTTPFile> fileParams, Dictionary <string, string> parameters, LuaFunction resultHandler, LuaFunction faultHandler, LuaFunction progressHandler) { _resultHandler = resultHandler; _faultHandler = faultHandler; _uploadProgressHandler = progressHandler; #if UNITY_ANDROID && !UNITY_EDITOR string appPath = luascriptcore.modules.foundation.Path.app(); AndroidJavaObject currentActivity = UNIEnv.getCurrentActivity(); AndroidJavaObject assetManager = currentActivity.Call <AndroidJavaObject> ("getAssets", new object[0]); #endif WWWForm form = new WWWForm(); if (fileParams != null) { foreach (KeyValuePair <string, HTTPFile> kv in fileParams) { HTTPFile file = kv.Value; string path = file.path; byte[] fileData = null; #if UNITY_ANDROID && !UNITY_EDITOR if (path.StartsWith(appPath) || !path.StartsWith("/")) { //应用包内文件 if (path.StartsWith(appPath)) { path = path.Substring(appPath.Length + 1); } AndroidJavaObject inputStream = assetManager.Call <AndroidJavaObject> ("open", path); 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); } fileData = new byte[ms.Length]; ms.Read(fileData, 0, (int)ms.Length); } finally { ms.Close(); } } } else { #endif FileStream fs = new FileStream(path, FileMode.Open); try { fileData = new byte[fs.Length]; fs.Read(fileData, 0, (int)fs.Length); } finally { fs.Close(); } #if UNITY_ANDROID && !UNITY_EDITOR } #endif if (fileData != null) { form.AddBinaryData(kv.Key, fileData, System.IO.Path.GetFileName(file.path), file.mimeType); } } } if (parameters != null) { foreach (KeyValuePair <string, string> kv in parameters) { form.AddField(kv.Key, kv.Value); } } _request = UnityWebRequest.Post(url, form); if (_request != null) { fillHeaders(); sendRequest(); } }
/// <summary> /// This method will run _restoreTransactions followed by _refreshMarketItemsDetails. /// </summary> protected override void _refreshInventory() { AndroidJNI.PushLocalFrame(100); jniStoreController.Call("refreshInventory"); AndroidJNI.PopLocalFrame(IntPtr.Zero); }
public void AndroidSendUpdate() { Debug.Log("AndroidSendUpdate"); AndroidJNI.AttachCurrentThread(); IntPtr instancePtr = AndroidJNI.CallStaticObjectMethod(pluginClass.GetRawClass(), AndroidJNI.GetStaticMethodID(pluginClass.GetRawClass(), "instance", "()Laudiotest/takeleap/com/playsound/PlaySoundExternal;"), new jvalue[] { }); IntPtr currentActivityPtr = AndroidJNI.GetStaticObjectField(unityClass.GetRawClass(), AndroidJNI.GetStaticFieldID(unityClass.GetRawClass(), "currentActivity", "Landroid/app/Activity;")); AndroidJNI.CallVoidMethod(instancePtr, AndroidJNI.GetMethodID(pluginClass.GetRawClass(), "SendVideoAudioProcess", "(ILandroid/content/Context;)V"), new jvalue[] { new jvalue() { i = SkypeManager.Instance.isCaller ? 1 : 2 }, new jvalue() { l = currentActivityPtr } }); IntPtr inputStreamPtr = AndroidJNI.CallObjectMethod(instancePtr, AndroidJNI.GetMethodID(pluginClass.GetRawClass(), "GetSendVideoProcessInputStream", "()Ljava/io/InputStream;"), new jvalue[] { }); IntPtr numsPtr = AndroidJNI.ToByteArray(newData); while (true) { int bytesRead = numDataPerRead; bytesRead = AndroidJNI.CallIntMethod(inputStreamPtr, AndroidJNI.GetMethodID(inputStreamClass.GetRawClass(), "read", "([BII)I"), new jvalue[] { new jvalue() { l = numsPtr }, new jvalue() { i = 0 }, new jvalue() { i = numDataPerRead } }); newData = AndroidJNIHelper.ConvertFromJNIArray <byte[]>(numsPtr); int index = SearchBytePatternAndroid(); Debug.Log("NNN " + bytesRead + " " + index); if (index != -1) { Buffer.BlockCopy(newData, 0, tempData, count, index); count += index; data = new byte[count]; Buffer.BlockCopy(tempData, 0, data, 0, count); index += 2; Buffer.BlockCopy(newData, index, tempData, 0, bytesRead - index); count = bytesRead - index; } else { Buffer.BlockCopy(newData, 0, tempData, count, bytesRead); count += bytesRead; } } AndroidJNI.DeleteLocalRef(numsPtr); }
/// <summary> /// Creates a list of all metadata stored in the Market (the items that have been purchased). /// The metadata includes the item's name, description, price, product id, etc... /// </summary> protected override void _refreshMarketItemsDetails() { AndroidJNI.PushLocalFrame(100); jniStoreController.Call("refreshMarketItemsDetails"); AndroidJNI.PopLocalFrame(IntPtr.Zero); }
private static void BurstlyCurrencyWrapper_updateBalancesFromServer() { jvalue[] args = new jvalue[0]; AndroidJNI.CallStaticVoidMethod(BurstlyPluginClass, methodID_updateBalancesFromServer, args); }
/// <summary> /// Initiates the restore transactions process. /// </summary> protected override void _restoreTransactions() { AndroidJNI.PushLocalFrame(100); jniStoreController.Call("restoreTransactions"); AndroidJNI.PopLocalFrame(IntPtr.Zero); }
static OuyaUnityPlugin() { try { { string strName = "tv/ouya/sdk/OuyaUnityPlugin"; _jcOuyaUnityPlugin = AndroidJNI.FindClass(strName); if (_jcOuyaUnityPlugin != IntPtr.Zero) { Debug.Log(string.Format("Found {0} class", strName)); } else { Debug.LogError(string.Format("Failed to find {0} class", strName)); return; } } { string strMethod = "<init>"; _jmConstructor = AndroidJNI.GetMethodID(_jcOuyaUnityPlugin, strMethod, "(Landroid/app/Activity;)V"); if (_jmConstructor != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "setDeveloperId"; _jmSetDeveloperId = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;)Ljava/lang/String;"); if (_jmSetDeveloperId != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "unityInitialized"; _jmUnityInitialized = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()V"); if (_jmUnityInitialized != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getGameData"; _jmGetGameData = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;)Ljava/lang/String;"); if (_jmGetGameData != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "putGameData"; _jmPutGameData = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;Ljava/lang/String;)V"); if (_jmPutGameData != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "fetchGamerInfo"; _jmFetchGamerInfo = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()V"); if (_jmFetchGamerInfo != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "addGetProduct"; _jmAddGetProduct = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;)V"); if (_jmAddGetProduct != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "debugGetProductList"; _jmDebugGetProductList = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()V"); if (_jmDebugGetProductList != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "clearGetProductList"; _jmClearGetProductList = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()V"); if (_jmClearGetProductList != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getProductsAsync"; _jmGetProductsAsync = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()V"); if (_jmGetProductsAsync != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "requestPurchaseAsync"; _jmRequestPurchaseAsync = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "(Ljava/lang/String;)Ljava/lang/String;"); if (_jmRequestPurchaseAsync != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } { string strMethod = "getReceiptsAsync"; _jmGetReceiptsAsync = AndroidJNI.GetStaticMethodID(_jcOuyaUnityPlugin, strMethod, "()V"); if (_jmGetReceiptsAsync != IntPtr.Zero) { Debug.Log(string.Format("Found {0} method", strMethod)); } else { Debug.LogError(string.Format("Failed to find {0} method", strMethod)); return; } } } catch (System.Exception) { Debug.LogError("Exception finding OuyaUnityPlugin class"); } }
public static string StatusForZone(string zone_id) { jvalue[] args = new jvalue[1]; args[0].l = AndroidJNI.NewStringUTF(zone_id); return(AndroidJNI.CallStaticStringMethod(class_UnityADC, method_statusForZone, args)); }