Created
April 9, 2021 05:00
-
-
Save lokeshsuryan/13d6f5197c803576bc1e15f52f735c55 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 System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using HuaweiService; | |
using HuaweiService.appmessage; | |
using HuaweiService.analytic; | |
using HuaweiService.push; | |
using Exception = HuaweiService.Exception; | |
public class APPMessaging : MonoBehaviour | |
{ | |
private HiAnalyticsInstance instance; | |
private AGConnectAppMessaging appMessaging; | |
private void Start() | |
{ | |
instance = HiAnalytics.getInstance(new Context()); | |
appMessaging = AGConnectAppMessaging.getInstance(); | |
appMessaging.setFetchMessageEnable(true); | |
appMessaging.setDisplayEnable(true); | |
instance.setAnalyticsEnabled(true); | |
getAAID(); | |
} | |
private void getAAID(){ | |
// Task result = instance.getAAID(); | |
Task id = HmsInstanceId.getInstance(new Context()).getAAID(); | |
id.addOnSuccessListener(new HmsSuccessListener<AAIDResult>((aaidResult) => | |
{ | |
string aaId = aaidResult.getId(); | |
Debug.Log("AAID==>> "+aaId); | |
})).addOnFailureListener(new HmsFailureListener((e) => | |
{ | |
Debug.Log("AAID==>> Failed"); | |
})); | |
} | |
public delegate void SuccessCallBack<T>(T o); | |
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); | |
} | |
} | |
} | |
public delegate void SuccessCallBack(AndroidJavaObject object); | |
public delegate void FailureCallBack(Exception e); | |
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); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment