90 lines
3.5 KiB
C#
Executable File
90 lines
3.5 KiB
C#
Executable File
using System.Collections.Generic;
|
|
|
|
namespace EFSDK
|
|
{
|
|
using UnityEngine;
|
|
|
|
public class EFSdkAndroid : MonoBehaviour
|
|
{
|
|
private string H5_Load_Succ = "H5_Load_Succ";
|
|
private string On_Resume = "onResume";
|
|
private string Can_Goback = "canGoback";
|
|
private string reqNotifyPermission = "reqNotifyPermission";
|
|
private string REQUEST_ADD_WIDGET_RESULT = "requestAddWidgetResult";
|
|
|
|
public void OnReceiverAnd(string message)
|
|
{
|
|
WLoom.QueueOnMainThread(_ =>
|
|
{
|
|
Debug.Log("Received message from Android: " + message);
|
|
if (message.Contains(On_Resume))
|
|
{
|
|
EFSdk.get().ActionCallback?.Invoke(EFSdk.ActionType.ON_RESUME, message);
|
|
}
|
|
if (message.Contains(Can_Goback))
|
|
{
|
|
EFSdk.get().mCanGobackAction?.Invoke(bool.Parse(message.Split('#')[1]));
|
|
}
|
|
|
|
if (message.Contains(H5_Load_Succ))
|
|
{
|
|
//GAM页面加载成功 Gam_Load_Succ@id
|
|
string[] parts = message.Split('@');
|
|
EFSdk.get().ActionCallback?.Invoke(EFSdk.ActionType.H5_Load_Succ, parts[1]);
|
|
}
|
|
|
|
if (message.StartsWith(reqNotifyPermission))
|
|
{
|
|
string[] flag = message.Split('#');
|
|
EFSdk.get().mReqNotifyPermissionAction?.Invoke(flag[1].Equals("1"));
|
|
}
|
|
|
|
if (message.StartsWith(REQUEST_ADD_WIDGET_RESULT))
|
|
{
|
|
string[] flag = message.Split('#');
|
|
EFSdk.get().actionRequestAddWidgetResult?.Invoke(flag[2].Equals("true"));
|
|
}
|
|
|
|
if (message.StartsWith("Event#"))
|
|
{
|
|
string[] eventKeys = message.Split('#');
|
|
if (eventKeys.Length > 0)
|
|
{
|
|
if (message.Contains("hd_h5_impression"))
|
|
{
|
|
//互动广告展示
|
|
string url = eventKeys[2];
|
|
EFSdk.get().HdH5ImpressionAction?.Invoke(url);
|
|
}
|
|
else if (eventKeys.Length == 2)
|
|
{
|
|
// 只有一个事件key
|
|
string eventKey = eventKeys[1];
|
|
EFSdk.get().ActionSDKEventCallback?.Invoke(eventKey, null);
|
|
}
|
|
else if (eventKeys.Length == 3)
|
|
{
|
|
// key-value事件
|
|
string eventKey = eventKeys[1];
|
|
string value = eventKeys[2];
|
|
}
|
|
else
|
|
{
|
|
//多属性事件
|
|
string eventKey = eventKeys[1];
|
|
Dictionary<string, string> attrs = new Dictionary<string, string>();
|
|
for (int i = 2; i < eventKeys.Length - 1; i += 2)
|
|
{
|
|
string key = eventKeys[i];
|
|
string value = eventKeys[i + 1];
|
|
attrs[key] = value;
|
|
}
|
|
|
|
EFSdk.get().ActionSDKEventCallback?.Invoke(eventKey, attrs);
|
|
}
|
|
}
|
|
}
|
|
}, "");
|
|
}
|
|
}
|
|
} |