Skip to content

Instantly share code, notes, and snippets.

@lokeshsuryan
Created April 2, 2021 06:54
Show Gist options
  • Save lokeshsuryan/d1ccee95e77ec82b4206e68b2d20729e to your computer and use it in GitHub Desktop.
Save lokeshsuryan/d1ccee95e77ec82b4206e68b2d20729e to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HuaweiService.apm;
public class APMService : MonoBehaviour
{
CustomTrace customTrace;
// Start is called before the first frame update
void Start()
{
customTrace = APMS.getInstance().createCustomTrace("testTrace");
}
// Update is called once per frame
void Update()
{
}
public void customTraceMeasureTest(){
customTrace.start();
Debug.Log ("Hello" + " world");
UnityEngine.Debug.Log("CustomTraceMeasureTest start");
customTrace.putMeasure("ProcessingTimes", 0);
for (int i = 0; i < 155; i++) {
customTrace.incrementMeasure("ProcessingTimes", 1);
}
long value = customTrace.getMeasure("ProcessingTimes");
Debug.Log("Measurename: ProcessingTimes, value: "+ value);
UnityEngine.Debug.Log("CustomTraceMeasureTest success");
showAndroidToastMessage("CustomTraceMeasureTest successfully completed");
}
private void showAndroidToastMessage(string message)
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject unityActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
if (unityActivity != null)
{
AndroidJavaClass toastClass = new AndroidJavaClass("android.widget.Toast");
unityActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
{
AndroidJavaObject toastObject = toastClass.CallStatic<AndroidJavaObject>("makeText", unityActivity, message, 0);
toastObject.Call("show");
}));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment