void Awake() { #if UNITY_ANDROID && ENABLE_PLUGIN android = new AndroidJavaObject(ObjectClassPath); android.Call("init", gameObject.name, "FacebookAgentReceiveAgentEvent"); logMapObject = new AndroidJavaObject("android.os.Bundle"); logMethodID = AndroidJNIHelper.GetMethodID(logMapObject.GetRawClass(), "putString", "(Ljava/lang/String;Ljava/lang/String;)V"); logClearID = AndroidJNIHelper.GetMethodID(logMapObject.GetRawClass(), "clear", "()V"); logMethodByteArray = AndroidJNIHelper.GetMethodID(logMapObject.GetRawClass(), "putByteArray", "(Ljava/lang/String;[B)V"); #endif _instance = this; }
public void logEvent(string eventId, Dictionary<string, string> parameters) { using(AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap")) { // Call 'put' via the JNI instead of using helper classes to avoid: // "JNI: Init'd AndroidJavaObject with null ptr!" IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] args = new object[2]; foreach(KeyValuePair<string, string> kvp in parameters) { using(AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key)) { using(AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value)) { args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } } } cls_FlurryAgent.CallStatic("logEvent", eventId, obj_HashMap); } }
// Calls a custom Graph API method with the key/value pairs in the Dictionary. Pass in a null dictionary if no parameters are needed. public static void graphRequest( string graphPath, string httpMethod, Dictionary<string,string> parameters ) { if( Application.platform != RuntimePlatform.Android ) return; // load up the Bundle using( var bundle = new AndroidJavaObject( "android.os.Bundle" ) ) { var putStringMethod = AndroidJNI.GetMethodID( bundle.GetRawClass(), "putString", "(Ljava/lang/String;Ljava/lang/String;)V" ); var args = new object[2]; // add all our dictionary elements into the Bundle if( parameters != null ) { foreach( var kv in parameters ) { args[0] = new AndroidJavaObject( "java.lang.String", kv.Key ); args[1] = new AndroidJavaObject( "java.lang.String", kv.Value ); AndroidJNI.CallObjectMethod( bundle.GetRawObject(), putStringMethod, AndroidJNIHelper.CreateJNIArgArray( args ) ); } } // call off to java land _facebookPlugin.Call( "graphRequest", graphPath, httpMethod, bundle ); } }
private AndroidJavaObject CreateJavaHashMap(Dictionary<string, string> storeKeys) { var j_HashMap = new AndroidJavaObject("java.util.HashMap"); IntPtr method_Put = AndroidJNIHelper.GetMethodID(j_HashMap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); if (storeKeys != null) { object[] args = new object[2]; foreach (KeyValuePair<string, string> kvp in storeKeys) { using (AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key)) { using (AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value)) { args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(j_HashMap.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } } } } return j_HashMap; }
public static void trackEvent(string eventStr, Hashtable chnlDetail) { using (AndroidJavaObject androidJavaObject = new AndroidJavaObject("java.util.HashMap", new object[0])) { IntPtr methodID = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] array = new object[2]; foreach (DictionaryEntry dictionaryEntry in chnlDetail) { using (AndroidJavaObject androidJavaObject2 = new AndroidJavaObject("java.lang.String", new object[] { dictionaryEntry.Key })) { using (AndroidJavaObject androidJavaObject3 = new AndroidJavaObject("java.lang.String", new object[] { dictionaryEntry.Value })) { array[0] = androidJavaObject2; array[1] = androidJavaObject3; AndroidJNI.CallObjectMethod(androidJavaObject.GetRawObject(), methodID, AndroidJNIHelper.CreateJNIArgArray(array)); } } } AdvertMgr.callSdkApi("trackEvent", new object[] { eventStr, androidJavaObject }); } }
//helpers public static AndroidJavaObject dictionaryToHashmap(Dictionary<string, string> dict) { AndroidJavaObject hashmap = new AndroidJavaObject("java.util.HashMap"); System.IntPtr methodPut = AndroidJNIHelper.GetMethodID(hashmap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] args = new object[2]; foreach(KeyValuePair<string, string> kvp in dict) { AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key); AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value); args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(hashmap.GetRawObject(), methodPut, AndroidJNIHelper.CreateJNIArgArray(args)); } return hashmap; }
public static void OnEvent(string actionId, Dictionary<string, object> parameters) { if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor && parameters != null && parameters.Count > 0 && parameters.Count <= 10) { int count = parameters.Count; AndroidJavaObject androidJavaObject = new AndroidJavaObject("java.util.HashMap", new object[] { count }); IntPtr methodID = AndroidJNIHelper.GetMethodID(androidJavaObject.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] array = new object[2]; foreach (KeyValuePair<string, object> current in parameters) { array[0] = new AndroidJavaObject("java.lang.String", new object[] { current.Key }); if (typeof(string).IsInstanceOfType(current.Value)) { array[1] = new AndroidJavaObject("java.lang.String", new object[] { current.Value }); } else { array[1] = new AndroidJavaObject("java.lang.Double", new object[] { string.Empty + current.Value }); } AndroidJNI.CallObjectMethod(androidJavaObject.GetRawObject(), methodID, AndroidJNIHelper.CreateJNIArgArray(array)); } if (TalkingDataGA.agent != null) { AndroidJavaObject @static = TalkingDataGA.unityClass.GetStatic<AndroidJavaObject>("currentActivity"); TalkingDataGA.agent.CallStatic("onEvent", new object[] { @static, actionId, androidJavaObject }); } } }
public void init(Dictionary<string, string> storeKeys=null) { if (!IsDevice()) return; using (AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap")) { IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); if (storeKeys != null) { object[] args = new object[2]; foreach (KeyValuePair<string, string> kvp in storeKeys) { using (AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key)) { using (AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value)) { args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } } } } _plugin.Call("init", obj_HashMap); } }
public void init(Options options) { if (!IsDevice()) { // Fake init process in the editor. For test purposes OpenIAB.EventManager.SendMessage("OnBillingSupported", ""); return; } using (var j_optionsBuilder = new AndroidJavaObject("org.onepf.oms.OpenIabHelper$Options$Builder")) { var clazz = j_optionsBuilder.GetRawClass(); var objPtr = j_optionsBuilder.GetRawObject(); j_optionsBuilder.Call<AndroidJavaObject>("setDiscoveryTimeout", options.discoveryTimeoutMs) .Call<AndroidJavaObject>("setCheckInventory", options.checkInventory) .Call<AndroidJavaObject>("setCheckInventoryTimeout", options.checkInventoryTimeoutMs) .Call<AndroidJavaObject>("setVerifyMode", (int) options.verifyMode); foreach (var pair in options.storeKeys) j_optionsBuilder.Call<AndroidJavaObject>("addStoreKey", pair.Key, pair.Value); var addPreferredStoreNameMethod = AndroidJNI.GetMethodID(clazz, "addPreferredStoreName", "([Ljava/lang/String;)Lorg/onepf/oms/OpenIabHelper$Options$Builder;"); var prms = new jvalue[1]; prms[0].l = AndroidJNIHelper.ConvertToJNIArray(options.prefferedStoreNames); AndroidJNI.CallObjectMethod(objPtr, addPreferredStoreNameMethod, prms); // Build options instance var buildMethod = AndroidJNI.GetMethodID(clazz, "build", "()Lorg/onepf/oms/OpenIabHelper$Options;"); var j_options = AndroidJNI.CallObjectMethod(objPtr, buildMethod, new jvalue[0]); // UnityPlugin.initWithOptions(OpenIabHelper.Options options); var initWithOptionsMethod = AndroidJNI.GetMethodID(_plugin.GetRawClass(), "initWithOptions", "(Lorg/onepf/oms/OpenIabHelper$Options;)V"); prms = new jvalue[1]; prms[0].l = j_options; AndroidJNI.CallVoidMethod(_plugin.GetRawObject(), initWithOptionsMethod, prms); } }
private static bool IsAndroidJavaObjectNull(AndroidJavaObject androidJavaObject) { return androidJavaObject == null || androidJavaObject.GetRawClass().ToInt32() == 0; }
public static void trackRichEvent(string eventName, Dictionary<string, string> eventValues){ using(AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap")) { IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] args = new object[2]; foreach(KeyValuePair<string, string> kvp in eventValues) { using(AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key)) { using(AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value)) { args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } } } using(AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { using(AndroidJavaObject cls_Activity = cls_UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity")) { cls_AppsFlyer.CallStatic("trackEvent",cls_Activity, eventName, obj_HashMap); } } } }
void makeJNICall(PickerType type, string[] items, long selectedItem) { if (isMobileRuntime == false) { return; } #if UNITY_ANDROID AndroidJavaObject obj_ArrayListItems = new AndroidJavaObject("java.util.ArrayList"); IntPtr method_Add = AndroidJNIHelper.GetMethodID(obj_ArrayListItems.GetRawClass(), "add", "(Ljava/lang/Object;)Z"); foreach (string item in items) { AndroidJNI.CallBooleanMethod(obj_ArrayListItems.GetRawObject(), method_Add, AndroidJNIHelper.CreateJNIArgArray(new string[] {item})); } Debug.Log(String.Format("Selected item -> {0}", selectedItem)); _pluginObject.Call("showPicker", (int)type, obj_ArrayListItems, selectedItem, "NativePicker"); #else return; #endif }
/// <summary> /// Set up the video player with the movie surface texture id /// </summary> void StartVideoPlayerOnTextureId() { int textureId = nativeTextureID; Debug.Log("SetUpVideoPlayer "); //IntPtr androidSurface = OVR_Media_Surface( textureId, 2880, 1440 ); IntPtr androidSurface = OVR_Media_Surface( textureId, 1920, 1080 ); mediaPlayer = new AndroidJavaObject("android/media/MediaPlayer"); // Can't use AndroidJavaObject.Call() with a jobject, must use low level interface //mediaPlayer.Call("setSurface", androidSurface); IntPtr setSurfaceMethodId = AndroidJNI.GetMethodID(mediaPlayer.GetRawClass(),"setSurface","(Landroid/view/Surface;)V"); jvalue[] parms = new jvalue[1]; parms[0] = new jvalue(); parms[0].l = androidSurface; AndroidJNI.CallObjectMethod(mediaPlayer.GetRawObject(), setSurfaceMethodId, parms); mediaPlayer.Call("setDataSource", "/storage/extSdCard/Oculus/zurichvideos/" + videoName); //mediaPlayer.Call("setDataSource", "/storage/sdcard0/zurichvideos/" + videoName); mediaPlayer.Call("prepare"); mediaPlayer.Call("setLooping", false); mediaPlayer.Call("start"); //return mediaPlayer; }
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); } return readLen; } finally { AndroidJNIHelper.DeleteJNIArgArray(args, array); } }
public void Track(string _namespace, string name, Dictionary<string, string> properties, GrowthAnalytics.TrackOption option) { using (AndroidJavaObject hashMap = new AndroidJavaObject("java.util.HashMap")) { System.IntPtr method_Put = AndroidJNIHelper.GetMethodID (hashMap.GetRawClass (), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] args = new object[2]; foreach (KeyValuePair<string, string> kvp in properties) { using (AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key)) { using (AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value)) { args [0] = k; args [1] = v; AndroidJNI.CallObjectMethod (hashMap.GetRawObject (), method_Put, AndroidJNIHelper.CreateJNIArgArray (args)); } } } AndroidJavaClass growthAnalyticsClass = new AndroidJavaClass( "com.growthbeat.analytics.GrowthAnalytics$TrackOption" ); AndroidJavaObject optionObject = growthAnalyticsClass.GetStatic<AndroidJavaObject>(option == GrowthAnalytics.TrackOption.TrackOptionOnce ? "ONCE" : "COUNTER"); growthAnalytics.Call("track", _namespace, name, hashMap, optionObject, null); } }
void Awake() { _instance = this; #if UNITY_ANDROID && ENABLE_PLUGIN android = new AndroidJavaObject(ObjectClassPath); android.Call("init", gameObject.name, "PlayStoreReceiveAgentEvent"); arraylist = new AndroidJavaObject("java.util.ArrayList"); ptrMethodAdd = AndroidJNI.GetMethodID(arraylist.GetRawClass(), "add", "(Ljava/lang/Object;)Z"); ptrMethodClear = AndroidJNI.GetMethodID(arraylist.GetRawClass(), "clear", "()V"); #endif }
private AndroidJavaObject convertMetadataToJavaHashMap(Dictionary<string, object> metaMap) { AndroidJavaObject meta_Hashmap = new AndroidJavaObject("java.util.HashMap"); if(metaMap != null) { 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") { if (metaKvp.Value != null && metaKvp.Value.Equals("yes") || metaKvp.Value.Equals("no")) { string value = metaKvp.Value.Equals("yes") ? "true" : "false"; meta_args[1] = new AndroidJavaObject("java.lang.Boolean", value); } else { meta_args[1] = new AndroidJavaObject("java.lang.String", 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)); } } } Debug.Log("Returning the Hashmap : " + meta_Hashmap); return meta_Hashmap; }
public override bool SdkSocialLoginCompleted(Dictionary<string, string> loginData) { bool succeeded = false; using (AndroidJavaObject hashMap = new AndroidJavaObject("java.util.HashMap")) { if (loginData != null) { System.IntPtr hashMapPutMethodId = AndroidJNI.GetMethodID ( hashMap.GetRawClass (), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); foreach (string key in loginData.Keys) { using (AndroidJavaObject hashMapPutMethodArgKey = new AndroidJavaObject("java.lang.String", key)) { using (AndroidJavaObject hashMapPutMethodArgValue = new AndroidJavaObject ("java.lang.String", loginData [key])) { object[] args = new object[2]; args [0] = hashMapPutMethodArgKey; args [1] = hashMapPutMethodArgValue; jvalue[] hashMapPutMethodArgs = AndroidJNIHelper.CreateJNIArgArray (args); AndroidJNI.CallObjectMethod ( hashMap.GetRawObject (), hashMapPutMethodId, hashMapPutMethodArgs); } } } } succeeded = m_jniFuelSDKUnity.CallStatic<bool>("sdkSocialLoginCompleted", hashMap); } return succeeded; }
public static Dictionary<string, string> MapToDictionary(AndroidJavaObject obj) { var mapClazz = new AndroidJavaObject("java.util.HashMap"); var setClazz = new AndroidJavaObject("java.util.HashSet"); IntPtr keySetMethod = AndroidJNIHelper.GetMethodID(obj.GetRawClass(), "keySet", "()Ljava/util/Set;"); IntPtr set = AndroidJNI.CallObjectMethod(obj.GetRawObject(), keySetMethod, new jvalue[] { }); IntPtr toArrayMethod = AndroidJNI.GetMethodID(setClazz.GetRawClass(), "toArray", "()[Ljava/lang/Object;"); IntPtr array = AndroidJNI.CallObjectMethod(set, toArrayMethod, new jvalue[] { }); var dict = new Dictionary<string, string>(); var keys = AndroidJNIHelper.ConvertFromJNIArray<string[]>(array); IntPtr getMethod = AndroidJNIHelper.GetMethodID(mapClazz.GetRawClass(), "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); foreach (var k in keys) { string v = AndroidJNI.CallStringMethod(obj.GetRawObject(), getMethod, new jvalue[] { new jvalue() { l = AndroidJNI.NewStringUTF(k) } }); dict.Add(k, v); } return dict; }
private static AndroidJavaObject DictionaryToMap(Dictionary<string, string> dict) { var map = new AndroidJavaObject("java.util.HashMap"); if (dict == null || dict.Count == 0) return map; IntPtr putMethod = AndroidJNIHelper.GetMethodID(map.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); var args = new object[2]; foreach (KeyValuePair<string, string> kvp in dict) { using (var k = new AndroidJavaObject("java.lang.String", kvp.Key)) { using (var v = new AndroidJavaObject("java.lang.String", kvp.Value)) { args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(map.GetRawObject(), putMethod, AndroidJNIHelper.CreateJNIArgArray(args)); } } } return map; }
public static void TrackEventWithParameters(string eventId, string eventLabel, Dictionary<string, object> parameters) { // Call plugin only when running on real device #if UNITY_IPHONE if (Application.platform != RuntimePlatform.OSXEditor) { if (parameters != null && parameters.Count > 0 && parameters.Count <= 10) { 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++; } _tdTrackEventParameters(eventId, eventLabel, keys, stringValues, numberValues, count); } else { _tdTrackEventLabel(eventId, eventLabel); } } #endif #if UNITY_ANDROID if (parameters != null && parameters.Count > 0 && parameters.Count <= 10) { 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)); } AndroidJavaClass tCAgent = new AndroidJavaClass("com.tendcloud.tenddata.TCAgent"); AndroidJavaClass unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currActivity = unityClass.GetStatic<AndroidJavaObject>("currentActivity"); tCAgent.CallStatic("onEvent", currActivity, eventId, eventLabel, map); } #endif }
/// <summary> /// Load the billing service. /// </summary> protected override void _loadBillingService() { if (StoreSettings.GPlayBP) { if (string.IsNullOrEmpty(StoreSettings.AndroidPublicKey) || StoreSettings.AndroidPublicKey == StoreSettings.AND_PUB_KEY_DEFAULT) { SoomlaUtils.LogError(TAG, "You chose Google Play billing service, but publicKey is not set!! Stopping here!!"); throw new ExitGUIException(); } if (StoreSettings.PlaySsvValidation) { if (string.IsNullOrEmpty(StoreSettings.PlayClientId) || StoreSettings.PlayClientId == StoreSettings.PLAY_CLIENT_ID_DEFAULT) { SoomlaUtils.LogError(TAG, "You chose Google Play Receipt Validation, but clientId is not set!! Stopping here!!"); throw new ExitGUIException(); } if (string.IsNullOrEmpty(StoreSettings.PlayClientSecret) || StoreSettings.PlayClientSecret == StoreSettings.PLAY_CLIENT_SECRET_DEFAULT) { SoomlaUtils.LogError(TAG, "You chose Google Play Receipt Validation, but clientSecret is not set!! Stopping here!!"); throw new ExitGUIException(); } if (string.IsNullOrEmpty(StoreSettings.PlayRefreshToken) || StoreSettings.PlayRefreshToken == StoreSettings.PLAY_REFRESH_TOKEN_DEFAULT) { SoomlaUtils.LogError(TAG, "You chose Google Play Receipt Validation, but refreshToken is not set!! Stopping here!!"); throw new ExitGUIException(); } } } AndroidJNI.PushLocalFrame(100); using(AndroidJavaClass jniSoomlaStoreClass = new AndroidJavaClass("com.soomla.store.SoomlaStore")) { jniSoomlaStore = jniSoomlaStoreClass.CallStatic<AndroidJavaObject>("getInstance"); bool success = jniSoomlaStore.Call<bool>("loadBillingService"); if (!success) { SoomlaUtils.LogError(TAG, "Couldn't load billing service! Billing functions won't work."); } } if (StoreSettings.GPlayBP) { using(AndroidJavaClass jniGooglePlayIabServiceClass = new AndroidJavaClass("com.soomla.store.billing.google.GooglePlayIabService")) { AndroidJavaObject jniGooglePlayIabService = jniGooglePlayIabServiceClass.CallStatic<AndroidJavaObject>("getInstance"); jniGooglePlayIabService.Call("setPublicKey", StoreSettings.AndroidPublicKey); using(AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap")) { IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] args = new object[2]; // client ID using(AndroidJavaObject k = new AndroidJavaObject("java.lang.String", "clientId")) { using(AndroidJavaObject v = new AndroidJavaObject("java.lang.String", StoreSettings.PlayClientId)) { args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } } // client secret using(AndroidJavaObject k = new AndroidJavaObject("java.lang.String", "clientSecret")) { using(AndroidJavaObject v = new AndroidJavaObject("java.lang.String", StoreSettings.PlayClientSecret)) { args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } } // refresh token using(AndroidJavaObject k = new AndroidJavaObject("java.lang.String", "refreshToken")) { using(AndroidJavaObject v = new AndroidJavaObject("java.lang.String", StoreSettings.PlayRefreshToken)) { args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } } // verifyOnServerFailure using(AndroidJavaObject k = new AndroidJavaObject("java.lang.String", "verifyOnServerFailure")) { using(AndroidJavaObject v = new AndroidJavaObject("java.lang.Boolean", StoreSettings.PlayVerifyOnServerFailure)) { args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } } jniGooglePlayIabService.Call("configVerifyPurchases", obj_HashMap); } jniGooglePlayIabServiceClass.SetStatic("AllowAndroidTestPurchases", StoreSettings.AndroidTestPurchases); } } AndroidJNI.PopLocalFrame(IntPtr.Zero); }
private static AndroidJavaObject ToJavaHashMap(Dictionary<string, string> dic) { var hashMap = new AndroidJavaObject("java.util.HashMap"); var putMethod = AndroidJNIHelper.GetMethodID(hashMap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); var arguments = new object[2]; foreach (var entry in dic) { using (var key = new AndroidJavaObject("java.lang.String", entry.Key)) { using (var val = new AndroidJavaObject("java.lang.String", entry.Value)) { arguments[0] = key; arguments[1] = val; AndroidJNI.CallObjectMethod(hashMap.GetRawObject(), putMethod, AndroidJNIHelper.CreateJNIArgArray(arguments)); } } // end using } // end foreach return hashMap; }
/// <summary> /// Set up the video player with the movie surface texture id /// </summary> AndroidJavaObject StartVideoPlayerOnTextureId( int textureId ) { Debug.Log ( "SetUpVideoPlayer " ); IntPtr androidSurface = OVR_Media_Surface( textureId ); AndroidJavaObject mediaPlayer = new AndroidJavaObject( "android/media/MediaPlayer" ); // Can't use AndroidJavaObject.Call() with a jobject, must use low level interface //mediaPlayer.Call( "setSurface", androidSurface ); IntPtr setSurfaceMethodId = AndroidJNI.GetMethodID( mediaPlayer.GetRawClass(),"setSurface","(Landroid/view/Surface;)V"); jvalue[] parms = new jvalue[1]; parms[0] = new jvalue(); parms[0].l = androidSurface; AndroidJNI.CallObjectMethod( mediaPlayer.GetRawObject(), setSurfaceMethodId, parms ); mediaPlayer.Call( "setDataSource", "/sdcard/oculus/Movies/Trailers/Night_of_the_living_Dead.mp4" ); mediaPlayer.Call( "prepare" ); mediaPlayer.Call( "setLooping", true ); mediaPlayer.Call( "start" ); return mediaPlayer; }
/// <summary> /// Dictionaries to map. /// </summary> /// <returns>The to map.</returns> /// <param name="dictionary">Dictionary.</param> private static AndroidJavaObject dictionaryToMap(Dictionary<string, object> dictionary) { using (AndroidJavaObject hashMap = new AndroidJavaObject("java.util.HashMap")) { if (dictionary != null) { System.IntPtr hashMapPutMethodId = AndroidJNI.GetMethodID ( hashMap.GetRawClass (), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); foreach (string key in dictionary.Keys) { using (AndroidJavaObject hashMapPutMethodArgKey = new AndroidJavaObject("java.lang.String", key)) { using (AndroidJavaObject hashMapPutMethodArgValue = new AndroidJavaObject ("java.lang.String", dictionary [key])) { object[] args = new object[2]; args [0] = hashMapPutMethodArgKey; args [1] = hashMapPutMethodArgValue; jvalue[] hashMapPutMethodArgs = AndroidJNIHelper.CreateJNIArgArray (args); AndroidJNI.CallObjectMethod ( hashMap.GetRawObject (), hashMapPutMethodId, hashMapPutMethodArgs); } } } } return hashMap; } }
int makeJNICall(string method, string caption, string message, string[] buttons, string[] values, bool cancellable) { if (isMobileRuntime == false) { return 0; } #if UNITY_ANDROID AndroidJavaObject obj_ArrayListButtons = new AndroidJavaObject("java.util.ArrayList"); AndroidJavaObject obj_ArrayListValues = new AndroidJavaObject("java.util.ArrayList"); Debug.Log("unity message: " + message); jvalue val = new jvalue(); val.l = AndroidJNI.NewStringUTF(message); IntPtr method_Add = AndroidJNIHelper.GetMethodID(obj_ArrayListButtons.GetRawClass(), "add", "(Ljava/lang/Object;)Z"); foreach (string button in buttons) { AndroidJNI.CallBooleanMethod(obj_ArrayListButtons.GetRawObject(), method_Add, AndroidJNIHelper.CreateJNIArgArray(new string[] {button})); } method_Add = AndroidJNIHelper.GetMethodID(obj_ArrayListValues.GetRawClass(), "add", "(Ljava/lang/Object;)Z"); foreach (string button in values) { AndroidJNI.CallBooleanMethod(obj_ArrayListValues.GetRawObject(), method_Add, AndroidJNIHelper.CreateJNIArgArray(new string[] {button})); } return _pluginObject.Call<int>(method, caption, message, obj_ArrayListButtons, obj_ArrayListValues, "NativeDialogs", cancellable); #else return 0; #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 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_IPHONE 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) { AndroidJavaObject activity = unityClass.GetStatic<AndroidJavaObject>("currentActivity"); agent.CallStatic("onEvent", activity, actionId, map); } #elif UNITY_WP8 TalkingDataGAWP.TalkingDataGA.onEvent(actionId, parameters); #endif } } }
// Starts up the billing service. This will also check to see if in app billing is supported and fire the appropriate event public static void init(Dictionary<string, string> storeKeys) { if (Application.platform != RuntimePlatform.Android) { OpenIABEventManager.SendMessage("OnBillingNotSupported", "editor mode"); return; } using (AndroidJavaObject obj_HashMap = new AndroidJavaObject("java.util.HashMap")) { IntPtr method_Put = AndroidJNIHelper.GetMethodID(obj_HashMap.GetRawClass(), "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); object[] args = new object[2]; foreach (KeyValuePair<string, string> kvp in storeKeys) { using (AndroidJavaObject k = new AndroidJavaObject("java.lang.String", kvp.Key)) { using (AndroidJavaObject v = new AndroidJavaObject("java.lang.String", kvp.Value)) { args[0] = k; args[1] = v; AndroidJNI.CallObjectMethod(obj_HashMap.GetRawObject(), method_Put, AndroidJNIHelper.CreateJNIArgArray(args)); } } } _plugin.Call("init", obj_HashMap); } }
/// <summary> /// Set up the video player with the movie surface texture id. /// </summary> AndroidJavaObject StartVideoPlayerOnTextureId(IntPtr textureId, string mediaPath) { Debug.Log("MoviePlayer: SetUpVideoPlayer"); IntPtr androidSurface = OVR_Media_Surface(textureId, 2880, 1440); Debug.Log("MoviePlayer: SetUpVideoPlayer after create surface"); AndroidJavaObject mediaPlayer = new AndroidJavaObject("android/media/MediaPlayer"); // Can't use AndroidJavaObject.Call() with a jobject, must use low level interface //mediaPlayer.Call("setSurface", androidSurface); IntPtr setSurfaceMethodId = AndroidJNI.GetMethodID(mediaPlayer.GetRawClass(),"setSurface","(Landroid/view/Surface;)V"); jvalue[] parms = new jvalue[1]; parms[0] = new jvalue(); parms[0].l = androidSurface; AndroidJNI.CallObjectMethod(mediaPlayer.GetRawObject(), setSurfaceMethodId, parms); try { mediaPlayer.Call("setDataSource", mediaPath); mediaPlayer.Call("prepare"); mediaPlayer.Call("setLooping", true); mediaPlayer.Call("start"); } catch (Exception e) { Debug.Log("Failed to start mediaPlayer with message " + e.Message); } return mediaPlayer; }