ATSDKAPIClient.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using AnyThinkAds.Common;
  5. using AnyThinkAds.Api;
  6. namespace AnyThinkAds.Android
  7. {
  8. public class ATSDKAPIClient : AndroidJavaProxy, IATSDKAPIClient
  9. {
  10. private AndroidJavaObject sdkInitHelper;
  11. private ATSDKInitListener sdkInitListener;
  12. public ATSDKAPIClient () : base("com.anythink.unitybridge.sdkinit.SDKInitListener")
  13. {
  14. this.sdkInitHelper = new AndroidJavaObject(
  15. "com.anythink.unitybridge.sdkinit.SDKInitHelper", this);
  16. }
  17. public void initSDK(string appId, string appKey)
  18. {
  19. this.initSDK(appId, appKey, null);
  20. }
  21. public void initSDK(string appId, string appKey, ATSDKInitListener listener)
  22. {
  23. Debug.Log("initSDK....");
  24. sdkInitListener = listener;
  25. try
  26. {
  27. if (this.sdkInitHelper != null)
  28. {
  29. this.sdkInitHelper.Call("initAppliction", appId, appKey);
  30. }
  31. }
  32. catch (System.Exception e)
  33. {
  34. System.Console.WriteLine("Exception caught: {0}", e);
  35. Debug.Log ("ATSDKAPIClient : error."+e.Message);
  36. }
  37. }
  38. public void getUserLocation(ATGetUserLocationListener listener)
  39. {
  40. ATNetTrafficListener netTrafficListener = new ATNetTrafficListener(listener);
  41. try
  42. {
  43. if (this.sdkInitHelper != null)
  44. {
  45. this.sdkInitHelper.Call("checkIsEuTraffic", netTrafficListener);
  46. }
  47. }
  48. catch (System.Exception e)
  49. {
  50. System.Console.WriteLine("Exception caught: {0}", e);
  51. Debug.Log("ATSDKAPIClient : error." + e.Message);
  52. }
  53. //implement getting location here
  54. }
  55. public void setGDPRLevel(int level)
  56. {
  57. Debug.Log ("setGDPRLevel....");
  58. try{
  59. if (this.sdkInitHelper != null) {
  60. this.sdkInitHelper.Call ("setGDPRLevel",level);
  61. }
  62. }catch(System.Exception e){
  63. System.Console.WriteLine("Exception caught: {0}", e);
  64. Debug.Log ("ATSDKAPIClient : error."+e.Message);
  65. }
  66. }
  67. public void showGDPRAuth()
  68. {
  69. Debug.Log ("showGDPRAuth....");
  70. try{
  71. if (this.sdkInitHelper != null) {
  72. this.sdkInitHelper.Call ("showGDPRAuth");
  73. }
  74. }catch(System.Exception e){
  75. System.Console.WriteLine("Exception caught: {0}", e);
  76. Debug.Log ("ATSDKAPIClient : error."+e.Message);
  77. }
  78. }
  79. public void showGDPRConsentDialog(ATConsentDismissListener listener)
  80. {
  81. Debug.Log ("showGDPRConsentDialog....");
  82. ATGDPRConsentDismissListener gdprConsentDismissListener = new ATGDPRConsentDismissListener(listener);
  83. try{
  84. if (this.sdkInitHelper != null) {
  85. this.sdkInitHelper.Call ("showGDPRConsentDialog", gdprConsentDismissListener);
  86. }
  87. }catch(System.Exception e){
  88. System.Console.WriteLine("Exception caught: {0}", e);
  89. Debug.Log ("ATSDKAPIClient : error."+e.Message);
  90. }
  91. }
  92. public void setChannel(string channel)
  93. {
  94. Debug.Log("setChannel....");
  95. try
  96. {
  97. if (this.sdkInitHelper != null)
  98. {
  99. this.sdkInitHelper.Call("setChannel", channel);
  100. }
  101. }
  102. catch (System.Exception e)
  103. {
  104. System.Console.WriteLine("Exception caught: {0}", e);
  105. Debug.Log("ATSDKAPIClient : error." + e.Message);
  106. }
  107. }
  108. public void setSubChannel(string subchannel)
  109. {
  110. Debug.Log("setSubChannel....");
  111. try
  112. {
  113. if (this.sdkInitHelper != null)
  114. {
  115. this.sdkInitHelper.Call("setSubChannel", subchannel);
  116. }
  117. }
  118. catch (System.Exception e)
  119. {
  120. System.Console.WriteLine("Exception caught: {0}", e);
  121. Debug.Log("ATSDKAPIClient : error." + e.Message);
  122. }
  123. }
  124. public void initCustomMap(string jsonMap)
  125. {
  126. Debug.Log("initCustomMap....");
  127. try
  128. {
  129. if (this.sdkInitHelper != null)
  130. {
  131. this.sdkInitHelper.Call("initCustomMap", jsonMap);
  132. }
  133. }
  134. catch (System.Exception e)
  135. {
  136. System.Console.WriteLine("Exception caught: {0}", e);
  137. Debug.Log("ATSDKAPIClient : error." + e.Message);
  138. }
  139. }
  140. public void setCustomDataForPlacementID(string customData, string placementID)
  141. {
  142. Debug.Log("setCustomDataForPlacementID....");
  143. try
  144. {
  145. if (this.sdkInitHelper != null)
  146. {
  147. this.sdkInitHelper.Call("initPlacementCustomMap", placementID, customData);
  148. }
  149. }
  150. catch (System.Exception e)
  151. {
  152. System.Console.WriteLine("Exception caught: {0}", e);
  153. Debug.Log("ATSDKAPIClient : error." + e.Message);
  154. }
  155. }
  156. public void setLogDebug(bool isDebug)
  157. {
  158. Debug.Log("setLogDebug....");
  159. try
  160. {
  161. if (this.sdkInitHelper != null)
  162. {
  163. this.sdkInitHelper.Call("setDebugLogOpen", isDebug);
  164. }
  165. }
  166. catch (System.Exception e)
  167. {
  168. System.Console.WriteLine("Exception caught: {0}", e);
  169. Debug.Log("ATSDKAPIClient : error." + e.Message);
  170. }
  171. }
  172. public void addNetworkGDPRInfo(int networkType, string mapJson)
  173. {
  174. // Debug.Log ("addNetworkGDPRInfo...." + networkType + "mapjson:"+mapJson);
  175. // try{
  176. // if (this.sdkInitHelper != null) {
  177. // this.sdkInitHelper.Call ("addNetworkGDPRInfo",networkType,mapJson);
  178. // }
  179. // }catch(System.Exception e){
  180. // System.Console.WriteLine("Exception caught: {0}", e);
  181. // Debug.Log ("ATSDKAPIClient : error."+e.Message);
  182. // }
  183. }
  184. public void initSDKSuccess(string appid)
  185. {
  186. Debug.Log("initSDKSuccess...unity3d.");
  187. if(sdkInitListener != null){
  188. sdkInitListener.initSuccess();
  189. }
  190. }
  191. public void initSDKError(string appid, string message)
  192. {
  193. Debug.Log("initSDKError..unity3d..");
  194. if (sdkInitListener != null)
  195. {
  196. sdkInitListener.initFail(message);
  197. }
  198. }
  199. public int getGDPRLevel()
  200. {
  201. Debug.Log("getGDPRLevel....");
  202. try
  203. {
  204. if (this.sdkInitHelper != null)
  205. {
  206. return this.sdkInitHelper.Call<int>("getGDPRLevel");
  207. }
  208. }
  209. catch (System.Exception e)
  210. {
  211. System.Console.WriteLine("Exception caught: {0}", e);
  212. Debug.Log("ATSDKAPIClient : error." + e.Message);
  213. }
  214. return 2; //UNKNOW
  215. }
  216. public bool isEUTraffic()
  217. {
  218. Debug.Log("isEUTraffic....");
  219. try
  220. {
  221. if (this.sdkInitHelper != null)
  222. {
  223. return this.sdkInitHelper.Call<bool>("isEUTraffic");
  224. }
  225. }
  226. catch (System.Exception e)
  227. {
  228. System.Console.WriteLine("Exception caught: {0}", e);
  229. Debug.Log("ATSDKAPIClient : error." + e.Message);
  230. }
  231. return false;
  232. }
  233. public void deniedUploadDeviceInfo(string deniedInfoString)
  234. {
  235. Debug.Log("deniedUploadDeviceInfo....");
  236. try
  237. {
  238. if (this.sdkInitHelper != null)
  239. {
  240. this.sdkInitHelper.Call("deniedUploadDeviceInfo", deniedInfoString);
  241. }
  242. }
  243. catch (System.Exception e)
  244. {
  245. System.Console.WriteLine("Exception caught: {0}", e);
  246. Debug.Log("ATSDKAPIClient : error." + e.Message);
  247. }
  248. }
  249. public void setExcludeBundleIdArray(string bundleIds)
  250. {
  251. Debug.Log("setExcludeBundleIdArray....");
  252. try
  253. {
  254. if (this.sdkInitHelper != null)
  255. {
  256. this.sdkInitHelper.Call("setExcludeBundleIdArray", bundleIds);
  257. }
  258. }
  259. catch (System.Exception e)
  260. {
  261. System.Console.WriteLine("Exception caught: {0}", e);
  262. Debug.Log("ATSDKAPIClient : error." + e.Message);
  263. }
  264. }
  265. public void setExcludeAdSourceIdArrayForPlacementID(string placementID, string adsourceIds)
  266. {
  267. Debug.Log("setExcludeAdSourceIdArrayForPlacementID....");
  268. try
  269. {
  270. if (this.sdkInitHelper != null)
  271. {
  272. this.sdkInitHelper.Call("setExcludeAdSourceIdArrayForPlacementID", placementID, adsourceIds);
  273. }
  274. }
  275. catch (System.Exception e)
  276. {
  277. System.Console.WriteLine("Exception caught: {0}", e);
  278. Debug.Log("ATSDKAPIClient : error." + e.Message);
  279. }
  280. }
  281. public void setSDKArea(int area)
  282. {
  283. Debug.Log("setSDKArea....");
  284. try
  285. {
  286. if (this.sdkInitHelper != null)
  287. {
  288. this.sdkInitHelper.Call("setSDKArea", area);
  289. }
  290. }
  291. catch (System.Exception e)
  292. {
  293. System.Console.WriteLine("Exception caught: {0}", e);
  294. Debug.Log("ATSDKAPIClient : error." + e.Message);
  295. }
  296. }
  297. public void getArea(ATGetAreaListener listener)
  298. {
  299. Debug.Log("getArea....");
  300. ATAreaListener areaListener = new ATAreaListener(listener);
  301. try
  302. {
  303. if (this.sdkInitHelper != null)
  304. {
  305. this.sdkInitHelper.Call("getArea", areaListener);
  306. }
  307. }
  308. catch (System.Exception e)
  309. {
  310. System.Console.WriteLine("Exception caught: {0}", e);
  311. Debug.Log("ATSDKAPIClient : error." + e.Message);
  312. }
  313. }
  314. public void setWXStatus(bool install)
  315. {
  316. Debug.Log("setWXStatus....");
  317. try
  318. {
  319. if (this.sdkInitHelper != null)
  320. {
  321. this.sdkInitHelper.Call("setWXStatus", install);
  322. }
  323. }
  324. catch (System.Exception e)
  325. {
  326. System.Console.WriteLine("Exception caught: {0}", e);
  327. Debug.Log("ATSDKAPIClient : error." + e.Message);
  328. }
  329. }
  330. public void setLocation(double longitude, double latitude)
  331. {
  332. Debug.Log("setLocation....");
  333. try
  334. {
  335. if (this.sdkInitHelper != null)
  336. {
  337. this.sdkInitHelper.Call("setLocation", longitude, latitude);
  338. }
  339. }
  340. catch (System.Exception e)
  341. {
  342. System.Console.WriteLine("Exception caught: {0}", e);
  343. Debug.Log("ATSDKAPIClient : error." + e.Message);
  344. }
  345. }
  346. public void showDebuggerUI() {
  347. showDebuggerUI("");
  348. }
  349. public void showDebuggerUI(string debugKey) {
  350. try
  351. {
  352. if (this.sdkInitHelper != null)
  353. {
  354. this.sdkInitHelper.Call("showDebuggerUI", debugKey);
  355. }
  356. }
  357. catch (System.Exception e)
  358. {
  359. System.Console.WriteLine("Exception caught: {0}", e);
  360. Debug.Log("ATSDKAPIClient : error." + e.Message);
  361. }
  362. }
  363. }
  364. }