Created
April 30, 2021 05:17
-
-
Save lokeshsuryan/c99ef04ae069f012a62b1f34ba5d18cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using HuaweiService.RemoteConfig; | |
using HuaweiService; | |
using Exception = HuaweiService.Exception; | |
using System; | |
using HuaweiService.analytic; | |
using HuaweiService.crash; | |
public class RemoteConfigManager : MonoBehaviour | |
{ | |
public static bool developerMode; | |
private HiAnalyticsInstance instance; | |
public delegate void SuccessCallBack<T>(T o); | |
public delegate void SuccessCallBack(AndroidJavaObject o); | |
public delegate void FailureCallBack(Exception e); | |
public void SetDeveloperMode() | |
{ | |
AGConnectConfig config; | |
config = AGConnectConfig.getInstance(); | |
developerMode = !developerMode; | |
config.setDeveloperMode(developerMode); | |
Debug.Log($"set developer mode to {developerMode}"); | |
} | |
public void sendReport() | |
{ | |
Application.ForceCrash(0); | |
} | |
public void showAllValues() | |
{ | |
AGConnectConfig config = AGConnectConfig.getInstance(); | |
if(config!=null) | |
{ | |
Map map = config.getMergedAll(); | |
var keySet = map.keySet(); | |
var keyArray = keySet.toArray(); | |
foreach (var key in keyArray) | |
{ | |
Debug.Log($"{key}: {map.getOrDefault(key, "default")}"); | |
} | |
}else | |
{ | |
Debug.Log(" No data "); | |
} | |
config.clearAll(); | |
} | |
void Start() | |
{ | |
instance = HiAnalytics.getInstance(new Context()); | |
instance.setAnalyticsEnabled(true); | |
CrashCollectON(); | |
AGConnectCrash.getInstance().setUserId("12345"); | |
SetDeveloperMode(); | |
SetXmlValue(); | |
} | |
public void setCustomValues(){ | |
AGConnectCrash.getInstance().setCustomKey("stringKey", "Crash Report"); | |
AGConnectCrash.getInstance().setCustomKey("booleanKey", false); | |
AGConnectCrash.getInstance().setCustomKey("doubleKey", 8.1); | |
AGConnectCrash.getInstance().setCustomKey("floatKey", 1.5f); | |
AGConnectCrash.getInstance().setCustomKey("intKey", 1); | |
AGConnectCrash.getInstance().setCustomKey("longKey", 9L); | |
} | |
public void CrashCollectON() | |
{ | |
AGConnectCrash.getInstance().enableCrashCollection(true); | |
} | |
public void SetXmlValue() | |
{ | |
var config = AGConnectConfig.getInstance(); | |
// get res id | |
int configId = AndroidUtil.GetId(new Context(), "xml", "remote_config"); | |
config.applyDefault(configId); | |
// get variable | |
Map map = config.getMergedAll(); | |
var keySet = map.keySet(); | |
var keyArray = keySet.toArray(); | |
config.applyDefault(map); | |
foreach (var key in keyArray) | |
{ | |
var value = config.getSource(key); | |
//Use the key and value ... | |
Debug.Log($"{key}: {config.getSource(key)}"); | |
} | |
} | |
public void GetCloudSettings() | |
{ | |
AGConnectConfig config = AGConnectConfig.getInstance(); | |
config.fetch().addOnSuccessListener(new HmsSuccessListener<ConfigValues>((ConfigValues configValues) => | |
{ | |
config.apply(configValues); | |
Debug.Log("===== ** Success ** ===="); | |
showAllValues(); | |
config.clearAll(); | |
})) | |
.addOnFailureListener(new HmsFailureListener((Exception e) => | |
{ | |
Debug.Log("activity failure " + e.toString()); | |
})); | |
} | |
public class HmsFailureListener:OnFailureListener | |
{ | |
public FailureCallBack CallBack; | |
public HmsFailureListener(FailureCallBack c) | |
{ | |
CallBack = c; | |
} | |
public override void onFailure(Exception arg0) | |
{ | |
if(CallBack !=null) | |
{ | |
CallBack.Invoke(arg0); | |
} | |
} | |
} | |
public class HmsSuccessListener<T>:OnSuccessListener | |
{ | |
public SuccessCallBack<T> CallBack; | |
public HmsSuccessListener(SuccessCallBack<T> c) | |
{ | |
CallBack = c; | |
} | |
public void onSuccess(T arg0) | |
{ | |
if(CallBack != null) | |
{ | |
CallBack.Invoke(arg0); | |
} | |
} | |
public override void onSuccess(AndroidJavaObject arg0) | |
{ | |
if(CallBack !=null) | |
{ | |
Type type = typeof(T); | |
IHmsBase ret = (IHmsBase)Activator.CreateInstance(type); | |
ret.obj = arg0; | |
CallBack.Invoke((T)ret); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment