-
Notifications
You must be signed in to change notification settings - Fork 2
/
AndroidMobLinkImpl.cs
executable file
·84 lines (67 loc) · 2.83 KB
/
AndroidMobLinkImpl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using UnityEngine;
using System;
using System.Collections;
namespace com.moblink.unity3d
{
#if UNITY_ANDROID
public class AndroidMobLinkImpl : MobLinkImpl {
public const string MOB_GAMEOBJECT_NAME = "MobLink";
public const string MOB_GETMOBID_CALLBACK_SUCCESS_METHOD = "_MobIdCallback";
public const string MOB_GETMOBID_CALLBACK_FAIL_METHOD = "_MobIdCallback";
public const string MOB_RESTORE_CALLBACK_METHOD = "_RestoreCallBack";
public override void setRestoreSceneListener ()
{
AndroidJavaClass javaMoblink = getAndroidMoblink();;
AndroidJavaObject l = new AndroidJavaObject ("com.mob.moblink.unity.RestoreSceneListener", MOB_GAMEOBJECT_NAME, MOB_RESTORE_CALLBACK_METHOD);
javaMoblink.CallStatic ("setRestoreSceneListener", l);
updateIntent ();
}
public override void GetMobId (MobLinkScene scene) {
GetMobId (scene.path, scene.source, scene.customParams);
}
private void GetMobId (string path, string source, Hashtable param) {
object map = hashtable2JavaMap(param);
object l = new AndroidJavaObject ("com.mob.moblink.unity.ActionListener", MOB_GAMEOBJECT_NAME, MOB_GETMOBID_CALLBACK_SUCCESS_METHOD, MOB_GETMOBID_CALLBACK_FAIL_METHOD);
// call java sdk
AndroidJavaClass javaMoblink = getAndroidMoblink ();
javaMoblink.CallStatic ("getMobID", map, path, source, l);
}
private void updateIntent() {
AndroidJavaObject activity = getAndroidContext ();
object intent = activity.Call<AndroidJavaObject> ("getIntent");
AndroidJavaClass javaMoblink = getAndroidMoblink ();
javaMoblink.CallStatic ("updateIntent", activity, intent);
}
private static AndroidJavaClass getAndroidMoblink()
{
return new AndroidJavaClass ("com.mob.moblink.MobLink");
}
private static AndroidJavaObject getAndroidContext()
{
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
return jo;
}
private static object getJavaString(String value)
{
return new AndroidJavaObject("java.lang.String", value);
}
private static object hashtable2JavaMap(Hashtable map)
{
AndroidJavaObject javaMap = new AndroidJavaObject ("java.util.HashMap");
IntPtr putMethod = AndroidJNIHelper.GetMethodID (javaMap.GetRawClass(), "put", "Ljava.lang.Object;(Ljava.lang.Object;Ljava.lang.Object;)", false);
foreach (string key in map.Keys)
{
string value = map[key].ToString();
object javaKey = getJavaString(key);
object javaValue = getJavaString(value);
object[] arr = new object[2];
arr[0] = javaKey; arr[1] = javaValue;
jvalue[] param = AndroidJNIHelper.CreateJNIArgArray(arr);
AndroidJNI.CallObjectMethod(javaMap.GetRawObject(), putMethod, param);
}
return javaMap;
}
}
#endif
}