AndroidImpl.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace cn.sharesdk.unity3d
  5. {
  6. #if UNITY_ANDROID
  7. public class AndroidImpl : ShareSDKImpl
  8. {
  9. private AndroidJavaObject ssdk;
  10. public AndroidImpl (GameObject go)
  11. {
  12. Debug.Log("AndroidImpl ===>>> AndroidImpl" );
  13. try{
  14. ssdk = new AndroidJavaObject("cn.sharesdk.unity3d.ShareSDKUtils", go.name, "_Callback");
  15. } catch(Exception e) {
  16. Console.WriteLine("{0} Exception caught.", e);
  17. }
  18. }
  19. public override void InitSDK (String appKey)
  20. {
  21. Debug.Log("AndroidImpl ===>>> InitSDK === " + appKey);
  22. if (ssdk != null)
  23. {
  24. ssdk.Call("initSDK", appKey);
  25. }
  26. }
  27. public override void InitSDK (String appKey,String appSecret)
  28. {
  29. Debug.Log("AndroidImpl ===>>> InitSDK === " + appKey);
  30. if (ssdk != null)
  31. {
  32. ssdk.Call("initSDK", appKey,appSecret);
  33. }
  34. }
  35. public override void PrepareLoopShare()
  36. {
  37. Debug.Log("AndroidImpl ===>>> PrepareLoopShare ");
  38. if (ssdk != null)
  39. {
  40. ssdk.Call("prepareLoopShare");
  41. }
  42. }
  43. public override void setChannelId()
  44. {
  45. Debug.Log("AndroidImpl ===>>> SetChannelId ");
  46. if (ssdk != null)
  47. {
  48. ssdk.Call("setChannelId");
  49. }
  50. }
  51. public override void SetPlatformConfig (Hashtable configs)
  52. {
  53. String json = MiniJSON.jsonEncode(configs);
  54. Debug.Log("AndroidImpl ===>>> SetPlatformConfig === " + json);
  55. if (ssdk != null)
  56. {
  57. ssdk.Call("setPlatformConfig", json);
  58. }
  59. }
  60. public override void Authorize (int reqID, PlatformType platform)
  61. {
  62. Debug.Log("AndroidImpl ===>>> Authorize" );
  63. if (ssdk != null)
  64. {
  65. ssdk.Call("authorize", reqID, (int)platform);
  66. }
  67. }
  68. public override void CancelAuthorize (PlatformType platform)
  69. {
  70. if (ssdk != null)
  71. {
  72. ssdk.Call("removeAccount", (int)platform);
  73. }
  74. }
  75. public override bool IsAuthorized (PlatformType platform)
  76. {
  77. if (ssdk != null)
  78. {
  79. return ssdk.Call<bool>("isAuthValid", (int)platform);
  80. }
  81. return false;
  82. }
  83. public override bool IsClientValid (PlatformType platform)
  84. {
  85. if (ssdk != null)
  86. {
  87. return ssdk.Call<bool>("isClientValid", (int)platform);
  88. }
  89. return false;
  90. }
  91. public override void GetUserInfo (int reqID, PlatformType platform)
  92. {
  93. Debug.Log("AndroidImpl ===>>> ShowUser" );
  94. if (ssdk != null)
  95. {
  96. ssdk.Call("showUser", reqID, (int)platform);
  97. }
  98. }
  99. public override void ShareContent (int reqID, PlatformType platform, ShareContent content)
  100. {
  101. Debug.Log("AndroidImpl ===>>> ShareContent to one platform" );
  102. ShareContent (reqID, new PlatformType[]{ platform }, content);
  103. }
  104. public override void ShareContent (int reqID, PlatformType[] platforms, ShareContent content)
  105. {
  106. Debug.Log("AndroidImpl ===>>> Share" );
  107. if (ssdk != null)
  108. {
  109. foreach (PlatformType platform in platforms)
  110. {
  111. ssdk.Call("shareContent", reqID, (int)platform, content.GetShareParamsStr());
  112. }
  113. }
  114. }
  115. public override void ShowPlatformList (int reqID, PlatformType[] platforms, ShareContent content, int x, int y)
  116. {
  117. ShowShareContentEditor(reqID, 0, content);
  118. }
  119. public override void ShowShareContentEditor (int reqID, PlatformType platform, ShareContent content)
  120. {
  121. Debug.Log("AndroidImpl ===>>> OnekeyShare platform ===" + (int)platform );
  122. if (ssdk != null)
  123. {
  124. ssdk.Call("onekeyShare", reqID, (int)platform, content.GetShareParamsStr());
  125. }
  126. }
  127. public override void GetFriendList (int reqID, PlatformType platform, int count, int page)
  128. {
  129. Debug.Log("AndroidImpl ===>>> GetFriendList" );
  130. if (ssdk != null)
  131. {
  132. ssdk.Call("getFriendList", reqID, (int)platform, count, page);
  133. }
  134. }
  135. public override void AddFriend (int reqID, PlatformType platform, String account)
  136. {
  137. Debug.Log("AndroidImpl ===>>> FollowFriend" );
  138. if (ssdk != null)
  139. {
  140. ssdk.Call("followFriend", reqID, (int)platform, account);
  141. }
  142. }
  143. public override Hashtable GetAuthInfo (PlatformType platform)
  144. {
  145. Debug.Log("AndroidImpl ===>>> GetAuthInfo" );
  146. if (ssdk != null)
  147. {
  148. String result = ssdk.Call<String>("getAuthInfo", (int)platform);
  149. return (Hashtable) MiniJSON.jsonDecode(result);
  150. }
  151. return new Hashtable ();
  152. }
  153. public override void DisableSSO (Boolean disable)
  154. {
  155. Debug.Log("AndroidImpl ===>>> DisableSSOWhenAuthorize" );
  156. if (ssdk != null)
  157. {
  158. ssdk.Call("disableSSOWhenAuthorize", disable);
  159. }
  160. }
  161. public override void setDisappearShareToast (Boolean isShow)
  162. {
  163. Debug.Log("AndroidImpl ===>>> setDisappearShareToast" );
  164. if (ssdk != null)
  165. {
  166. ssdk.Call("setDisappearShareToast", isShow);
  167. }
  168. }
  169. public override void ShareWithContentName (int reqId, PlatformType platform, string contentName, Hashtable customFields)
  170. {
  171. Debug.Log("#WARING : Do not support this feature in Android " );
  172. }
  173. public override void ShowPlatformListWithContentName (int reqId, string contentName, Hashtable customFields, PlatformType[] platforms, int x, int y)
  174. {
  175. Debug.Log("#WARING : Do not support this feature in Android " );
  176. }
  177. public override void ShowShareContentEditorWithContentName (int reqId, PlatformType platform, string contentName, Hashtable customFields)
  178. {
  179. Debug.Log("#WARING : Do not support this feature in Android " );
  180. }
  181. public override bool openMiniProgram (String userName, String path, int miniProgramType)
  182. {
  183. // wait for implementation
  184. return false;
  185. }
  186. public override void getWXRequestToken()
  187. {
  188. Debug.Log("#WARING : Do not support this feature in Android" );
  189. }
  190. public override void getWXRefreshToken()
  191. {
  192. Debug.Log("#WARING : Do not support this feature in Android" );
  193. }
  194. public override void sendWXRefreshToken(String token)
  195. {
  196. Debug.Log("#WARING : Do not support this feature in Android" );
  197. }
  198. public override void sendWXRequestToken(String uid, String token)
  199. {
  200. Debug.Log("#WARING : Do not support this feature in Android" );
  201. }
  202. public override void isClientValidForAndroid(int reqID,PlatformType platform)
  203. {
  204. Debug.Log("AndroidImpl ===>>> isClientValidForAndroid" );
  205. if (ssdk != null)
  206. {
  207. ssdk.Call("isClientValidForAndroid", reqID, (int)platform);
  208. }
  209. }
  210. }
  211. #endif
  212. }