// Start is called before the first frame update void Start() { AndroidJavaObject unityPlayerActivity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currentActivity = unityPlayerActivity.GetStatic <AndroidJavaObject>("currentActivity"); AndroidJavaObject context = currentActivity.Call <AndroidJavaObject>("getApplicationContext"); var chabok = new ChabokPush(); chabok.Init(context, unityPlayerActivity, "APP_ID/SENDER_ID", "API_KEY", "USERNAME", "PASSWORD"); chabok.SetDevelopment(true); var userId = chabok.GetUserId(); if (userId != null) { chabok.Register(userId); } else { chabok.RegisterAsGuest(); } var callback = new AndroidPluginCallback(); callback.OnSuccess += (count) => { }; callback.OnError += (exception) => { }; chabok.AddTag("Test", callback); chabok.Track("LIKE"); }
public void RemoveTag(string tagName, AndroidPluginCallback callback = null) { #if UNITY_ANDROID androidChabokPush.CallStatic("removeTag", tagName, callback); #elif UNITY_IOS iosRemoveTag(tagName); #endif }
private void CheckPacketLoss() { if (!pingTestInProgress) { #if UNITY_STANDALONE System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); PingOptions options = new PingOptions(); string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes(data); // 32 bytes of data var pingAmount = 4; var failedPings = 0; var latencySum = 0; for (int i = 0; i < pingAmount; i++) { PingReply reply = ping.Send(GlobalConstants.mediaServerAddress, 1000, buffer, options); if (reply != null) { if (reply.Status != IPStatus.Success) { failedPings += 1; } else { latencySum += (int)reply.RoundtripTime; } } } float averagePing = (latencySum / pingAmount); latency = averagePing; packetLoss = (Convert.ToDouble(failedPings) / Convert.ToDouble(pingAmount) * 100).ToString() + " %"; Debug.Log("Ping test: " + averagePing + "|| Loss : " + packetLoss.ToString() + " %", true); pingTestInProgress = false; } #endif #if UNITY_ANDROID if (Application.platform == RuntimePlatform.Android) { AndroidJavaObject networkInfo = new AndroidJavaObject("com.kuiperx.networkinformation.NetworkInformation"); AndroidPluginCallback callback = new AndroidPluginCallback(); callback.SetCallback(CheckPacketLossCallback); UnityEngine.Debug.Log("Starting Ping Test"); networkInfo.Call("GetNetworkStats", new object[] { GlobalConstants.mediaServerAddress, callback }); } #endif }
public static void Initialize() { if (Callback == null) { Callback = new AndroidPluginCallback(pluginName); } bool success = PluginInstance.Call <bool>("initialize", javaUnityActivity, Callback); if (!success) { Debug.LogError("BeaconWalletPlugin could not be initialized"); } }
void AttachPlugin() { if (Application.isEditor) { return; } //SetScreenBrightness (); Debug.Log("Attach plugin"); AndroidJNI.AttachCurrentThread(); AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject jo = jc.GetStatic <AndroidJavaObject>("currentActivity"); AndroidJavaObject jd = jo.Call <AndroidJavaObject>("getCurrentFocus"); plugin = new AndroidPluginCallback(); jd.Call("setOnCapturedPointerListener", plugin); }
void InitPlugin() { AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); activity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity"); activity.Call("runOnUiThread", new AndroidJavaRunnable(() => { plugin = new AndroidJavaObject( "com.example.matthew.webViewPlugin.WebBridge"); })); activity.Call("runOnUiThread", new AndroidJavaRunnable(() => { plugin.Call("init"); })); //set callback AndroidPluginCallback androidPluginCallback = new AndroidPluginCallback { webController = this }; activity.Call("runOnUiThread", new AndroidJavaRunnable(() => { plugin.Call("SetUnityBitmapCallback", androidPluginCallback); })); }
/// <summary> /// Removes the tag. /// </summary> /// <param name="tagName">Tag name.</param> /// <param name="callback">Callback.</param> public void RemoveTag(string tagName, AndroidPluginCallback callback) { AdpPushClientInstance.Call("removeTag", tagName, callback); }
void Start() { //txt.color = Color.white; chabokPush = ChabokPush.GetInstance(); #if UNITY_ANDROID callback = new AndroidPluginCallback(); //callback.OnSuccess += (count) => //{ // Log("add tag on success"); //}; //callback.OnError += (exception) => //{ // Log("add tag on failure"); //}; //String userId = chbokPush.CallStatic<String>("getUserId"); //chbokPush.CallStatic("addTag", "Smooke", callback); //chbokPush.CallStatic("setUserAttribute", "rating"); //chbokPush.CallStatic("unsetUserAttribute", "rating"); //var UserAttributes = chbokPush.CallStatic<AndroidJavaObject>("getUserAttributes"); #endif chabokPush.Login("SMOOKE"); Log(" Chabok --> Login : Succeeded"); chabokPush.AddTag("Hoss"); Log(" Chabok --> AddTag : Succeeded"); var birthdayDate = new DateTime(1993, 5, 19, 20, 10, 33); string[] favorites = { "Sport", "TV", "Book", "Coding" }; Dictionary <string, object> attributes = new Dictionary <string, object>(); attributes.Add("FirstName", "Hossein"); attributes.Add("Age", 26); attributes.Add("Rating", 20); attributes.Add("Ration", 3.85); attributes.Add("Male", false); attributes.Add("Birthday", birthdayDate); attributes.Add("Favorites", favorites); chabokPush.SetUserAttributes(attributes); Log(" Chabok --> SetUserAttributes : Succeeded"); chabokPush.IncrementUserAttribute("Age", 2.0); Log(" Chabok --> IncrementUserAttribute : Succeeded"); chabokPush.DecrementUserAttribute("Rating", 7.0); Log(" Chabok --> DecrementUserAttribute : Succeeded"); chabokPush.AddToUserAttributeArray("Favorites", "Sleeping"); Log(" Chabok --> AddToUserAttributeArray : Succeeded"); //Log(" Chabok --> UserAttributes : " + chabokPush.chabokGetUserAttributes()); chabokPush.RemoveFromUserAttributeArray("Favorites", "Book"); Log(" Chabok --> RemoveFromUserAttributeArray : Succeeded"); var expDate = new DateTime(2021, 10, 14, 11, 22, 33); string[] editedFields = { "name", "family", "phone" }; Dictionary <string, object> eventData = new Dictionary <string, object>(); eventData.Add("Edited Profile Title2", "Smooke"); eventData.Add("Edited2", false); eventData.Add("Edited items2", 12); eventData.Add("ExpDate", expDate); eventData.Add("EditedFields", editedFields); chabokPush.Track("Profile Edits", eventData); Log(" Chabok --> Track : Succeeded"); chabokPush.TrackRevenue(20000.0); Log(" Chabok --> TrackRevenue : Succeeded"); var purchaseDate = new DateTime(2021, 10, 14, 11, 22, 33); string[] card = { "rice", "tuna" }; Dictionary <string, object> revenueDic = new Dictionary <string, object>(); revenueDic.Add("Badge", "VIP"); revenueDic.Add("Discount", "18%"); revenueDic.Add("PurchaseDate", purchaseDate); revenueDic.Add("Card", card); chabokPush.TrackPurchase("VIP Purchase", 500000.0, "IRR", revenueDic); Log(" Chabok --> TrackPurchase : Succeeded"); }