AndroidAgent.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. #if UNITY_ANDROID
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System;
  6. public class AndroidAgent : IronSourceIAgent
  7. {
  8. private static AndroidJavaObject _androidBridge;
  9. private readonly static string AndroidBridge = "com.ironsource.unity.androidbridge.AndroidBridge";
  10. private const string REWARD_AMOUNT = "reward_amount";
  11. private const string REWARD_NAME = "reward_name";
  12. private const string PLACEMENT_NAME = "placement_name";
  13. public AndroidAgent ()
  14. {
  15. Debug.Log ("AndroidAgent ctr");
  16. }
  17. #region IronSourceIAgent implementation
  18. private AndroidJavaObject getBridge ()
  19. {
  20. if (_androidBridge == null)
  21. using (var pluginClass = new AndroidJavaClass( AndroidBridge ))
  22. _androidBridge = pluginClass.CallStatic<AndroidJavaObject> ("getInstance");
  23. return _androidBridge;
  24. }
  25. public void reportAppStarted ()
  26. {
  27. getBridge ().Call ("reportAppStarted");
  28. }
  29. //******************* Base API *******************//
  30. public void onApplicationPause (bool pause)
  31. {
  32. if (pause)
  33. {
  34. getBridge ().Call ("onPause");
  35. }
  36. else
  37. {
  38. getBridge ().Call ("onResume");
  39. }
  40. }
  41. public void setAge (int age)
  42. {
  43. getBridge ().Call ("setAge", age);
  44. }
  45. public void setGender (string gender)
  46. {
  47. getBridge ().Call ("setGender", gender);
  48. }
  49. public void setMediationSegment (string segment)
  50. {
  51. getBridge ().Call ("setMediationSegment", segment);
  52. }
  53. public string getAdvertiserId ()
  54. {
  55. return getBridge ().Call<string> ("getAdvertiserId");
  56. }
  57. public void validateIntegration ()
  58. {
  59. getBridge ().Call ("validateIntegration");
  60. }
  61. public void shouldTrackNetworkState (bool track)
  62. {
  63. getBridge ().Call ("shouldTrackNetworkState", track);
  64. }
  65. public bool setDynamicUserId (string dynamicUserId)
  66. {
  67. return getBridge ().Call<bool> ("setDynamicUserId", dynamicUserId);
  68. }
  69. public void setAdaptersDebug(bool enabled)
  70. {
  71. getBridge ().Call ("setAdaptersDebug", enabled);
  72. }
  73. //******************* SDK Init *******************//
  74. public void setUserId(string userId) {
  75. getBridge ().Call ("setUserId", userId);
  76. }
  77. public void init(string appKey)
  78. {
  79. getBridge ().Call ("setPluginData", "Unity", IronSource.pluginVersion (), IronSource.unityVersion ());
  80. getBridge ().Call ("init", appKey);
  81. }
  82. public void init (string appKey, params string[] adUnits)
  83. {
  84. getBridge ().Call ("setPluginData", "Unity", IronSource.pluginVersion (), IronSource.unityVersion ());
  85. getBridge ().Call ("init", appKey, adUnits);
  86. }
  87. public void initISDemandOnly (string appKey, params string[] adUnits)
  88. {
  89. getBridge ().Call ("setPluginData", "Unity", IronSource.pluginVersion (), IronSource.unityVersion ());
  90. getBridge ().Call ("initISDemandOnly", appKey, adUnits);
  91. }
  92. //******************* RewardedVideo API *******************//
  93. public void showRewardedVideo ()
  94. {
  95. getBridge ().Call ("showRewardedVideo");
  96. }
  97. public void showRewardedVideo (string placementName)
  98. {
  99. getBridge ().Call ("showRewardedVideo", placementName);
  100. }
  101. public bool isRewardedVideoAvailable ()
  102. {
  103. return getBridge ().Call<bool> ("isRewardedVideoAvailable");
  104. }
  105. public bool isRewardedVideoPlacementCapped (string placementName)
  106. {
  107. return getBridge ().Call<bool> ("isRewardedVideoPlacementCapped", placementName);
  108. }
  109. public IronSourcePlacement getPlacementInfo (string placementName)
  110. {
  111. string placementInfo = getBridge ().Call<string> ("getPlacementInfo", placementName);
  112. IronSourcePlacement pInfo = null;
  113. if (placementInfo != null) {
  114. Dictionary<string,object> pInfoDic = IronSourceJSON.Json.Deserialize (placementInfo) as Dictionary<string,object>;
  115. string pName = pInfoDic [PLACEMENT_NAME].ToString ();
  116. string rName = pInfoDic [REWARD_NAME].ToString ();
  117. int rAmount = Convert.ToInt32 (pInfoDic [REWARD_AMOUNT].ToString ());
  118. pInfo = new IronSourcePlacement (pName, rName, rAmount);
  119. }
  120. return pInfo;
  121. }
  122. public void setRewardedVideoServerParams(Dictionary<string, string> parameters) {
  123. string json = IronSourceJSON.Json.Serialize (parameters);
  124. getBridge ().Call ("setRewardedVideoServerParams", json);
  125. }
  126. public void clearRewardedVideoServerParams() {
  127. getBridge ().Call ("clearRewardedVideoServerParams");
  128. }
  129. //******************* RewardedVideo DemandOnly API *******************//
  130. public void showISDemandOnlyRewardedVideo (string instanceId)
  131. {
  132. getBridge ().Call ("showISDemandOnlyRewardedVideo",instanceId);
  133. }
  134. public void showISDemandOnlyRewardedVideo (string instanceId, string placementName)
  135. {
  136. getBridge ().Call ("showISDemandOnlyRewardedVideo", instanceId, placementName);
  137. }
  138. public bool isISDemandOnlyRewardedVideoAvailable (string instanceId)
  139. {
  140. return getBridge ().Call<bool> ("isISDemandOnlyRewardedVideoAvailable", instanceId);
  141. }
  142. //******************* Interstitial API *******************//
  143. public void loadInterstitial ()
  144. {
  145. getBridge ().Call ("loadInterstitial");
  146. }
  147. public void showInterstitial ()
  148. {
  149. getBridge ().Call ("showInterstitial");
  150. }
  151. public void showInterstitial (string placementName)
  152. {
  153. getBridge ().Call ("showInterstitial", placementName);
  154. }
  155. public bool isInterstitialReady ()
  156. {
  157. return getBridge ().Call<bool> ("isInterstitialReady");
  158. }
  159. public bool isInterstitialPlacementCapped (string placementName)
  160. {
  161. return getBridge ().Call<bool> ("isInterstitialPlacementCapped", placementName);
  162. }
  163. //******************* Interstitial DemandOnly API *******************//
  164. public void loadISDemandOnlyInterstitial (string instanceId)
  165. {
  166. getBridge ().Call ("loadISDemandOnlyInterstitial",instanceId);
  167. }
  168. public void showISDemandOnlyInterstitial (string instanceId)
  169. {
  170. getBridge ().Call ("showISDemandOnlyInterstitial",instanceId);
  171. }
  172. public void showISDemandOnlyInterstitial (string instanceId, string placementName)
  173. {
  174. getBridge ().Call ("showISDemandOnlyInterstitial", instanceId, placementName);
  175. }
  176. public bool isISDemandOnlyInterstitialReady (string instanceId)
  177. {
  178. return getBridge ().Call<bool> ("isISDemandOnlyInterstitialReady",instanceId);
  179. }
  180. //******************* Offerwall API *******************//
  181. public void showOfferwall ()
  182. {
  183. getBridge ().Call ("showOfferwall");
  184. }
  185. public void showOfferwall (string placementName)
  186. {
  187. getBridge ().Call ("showOfferwall", placementName);
  188. }
  189. public void getOfferwallCredits ()
  190. {
  191. getBridge ().Call ("getOfferwallCredits");
  192. }
  193. public bool isOfferwallAvailable ()
  194. {
  195. return getBridge ().Call<bool> ("isOfferwallAvailable");
  196. }
  197. //******************* Banner API *******************//
  198. public void loadBanner (IronSourceBannerSize size, IronSourceBannerPosition position)
  199. {
  200. getBridge ().Call ("loadBanner", (int)size, (int)position);
  201. }
  202. public void loadBanner (IronSourceBannerSize size, IronSourceBannerPosition position, string placementName)
  203. {
  204. getBridge ().Call ("loadBanner", (int)size, (int)position, placementName);
  205. }
  206. public void destroyBanner()
  207. {
  208. getBridge ().Call ("destroyBanner");
  209. }
  210. public void displayBanner()
  211. {
  212. getBridge ().Call ("displayBanner");
  213. }
  214. public void hideBanner()
  215. {
  216. getBridge ().Call ("hideBanner");
  217. }
  218. public bool isBannerPlacementCapped(string placementName)
  219. {
  220. return getBridge ().Call<bool> ("isBannerPlacementCapped", placementName);
  221. }
  222. public void setSegment(IronSourceSegment segment)
  223. {
  224. Dictionary <string,string> dict = segment.getSegmentAsDict ();
  225. string json = IronSourceJSON.Json.Serialize (dict);
  226. getBridge ().Call ("setSegment", json);
  227. }
  228. public void setConsent(bool consent)
  229. {
  230. getBridge().Call("setConsent",consent);
  231. }
  232. #endregion
  233. }
  234. #endif