AndroidImpl.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 SetPlatformConfig (Hashtable configs)
  36. {
  37. String json = ShareSDKMiniJSON.jsonEncode(configs);
  38. Debug.Log("AndroidImpl ===>>> SetPlatformConfig === " + json);
  39. if (ssdk != null)
  40. {
  41. ssdk.Call("setPlatformConfig", json);
  42. }
  43. }
  44. public override void Authorize (int reqID, PlatformType platform)
  45. {
  46. Debug.Log("AndroidImpl ===>>> Authorize" );
  47. if (ssdk != null)
  48. {
  49. ssdk.Call("authorize", reqID, (int)platform);
  50. }
  51. }
  52. public override void CancelAuthorize (PlatformType platform)
  53. {
  54. if (ssdk != null)
  55. {
  56. ssdk.Call("removeAccount", (int)platform);
  57. }
  58. }
  59. public override bool IsAuthorized (PlatformType platform)
  60. {
  61. if (ssdk != null)
  62. {
  63. return ssdk.Call<bool>("isAuthValid", (int)platform);
  64. }
  65. return false;
  66. }
  67. public override bool IsClientValid (PlatformType platform)
  68. {
  69. if (ssdk != null)
  70. {
  71. return ssdk.Call<bool>("isClientValid", (int)platform);
  72. }
  73. return false;
  74. }
  75. public override void GetUserInfo (int reqID, PlatformType platform)
  76. {
  77. Debug.Log("AndroidImpl ===>>> ShowUser" );
  78. if (ssdk != null)
  79. {
  80. ssdk.Call("showUser", reqID, (int)platform);
  81. }
  82. }
  83. public override void ShareContent (int reqID, PlatformType platform, ShareContent content)
  84. {
  85. Debug.Log("AndroidImpl ===>>> ShareContent to one platform" );
  86. ShareContent (reqID, new PlatformType[]{ platform }, content);
  87. }
  88. public override void ShareContent (int reqID, PlatformType[] platforms, ShareContent content)
  89. {
  90. Debug.Log("AndroidImpl ===>>> Share" );
  91. if (ssdk != null)
  92. {
  93. foreach (PlatformType platform in platforms)
  94. {
  95. ssdk.Call("shareContent", reqID, (int)platform, content.GetShareParamsStr());
  96. }
  97. }
  98. }
  99. public override void ShowPlatformList (int reqID, PlatformType[] platforms, ShareContent content, int x, int y)
  100. {
  101. ShowShareContentEditor(reqID, 0, content);
  102. }
  103. public override void ShowShareContentEditor (int reqID, PlatformType platform, ShareContent content)
  104. {
  105. Debug.Log("AndroidImpl ===>>> OnekeyShare platform ===" + (int)platform );
  106. if (ssdk != null)
  107. {
  108. ssdk.Call("onekeyShare", reqID, (int)platform, content.GetShareParamsStr());
  109. }
  110. }
  111. public override void GetFriendList (int reqID, PlatformType platform, int count, int page)
  112. {
  113. Debug.Log("AndroidImpl ===>>> GetFriendList" );
  114. if (ssdk != null)
  115. {
  116. ssdk.Call("getFriendList", reqID, (int)platform, count, page);
  117. }
  118. }
  119. public override void AddFriend (int reqID, PlatformType platform, String account)
  120. {
  121. Debug.Log("AndroidImpl ===>>> FollowFriend" );
  122. if (ssdk != null)
  123. {
  124. ssdk.Call("followFriend", reqID, (int)platform, account);
  125. }
  126. }
  127. public override Hashtable GetAuthInfo (PlatformType platform)
  128. {
  129. Debug.Log("AndroidImpl ===>>> GetAuthInfo" );
  130. if (ssdk != null)
  131. {
  132. String result = ssdk.Call<String>("getAuthInfo", (int)platform);
  133. return (Hashtable)ShareSDKMiniJSON.jsonDecode(result);
  134. }
  135. return new Hashtable ();
  136. }
  137. public override void DisableSSO (Boolean disable)
  138. {
  139. Debug.Log("AndroidImpl ===>>> DisableSSOWhenAuthorize" );
  140. if (ssdk != null)
  141. {
  142. ssdk.Call("disableSSOWhenAuthorize", disable);
  143. }
  144. }
  145. public override void ShareWithContentName (int reqId, PlatformType platform, string contentName, Hashtable customFields)
  146. {
  147. Debug.Log("#WARING : Do not support this feature in Android temporarily" );
  148. }
  149. public override void ShowPlatformListWithContentName (int reqId, string contentName, Hashtable customFields, PlatformType[] platforms, int x, int y)
  150. {
  151. Debug.Log("#WARING : Do not support this feature in Android temporarily" );
  152. }
  153. public override void ShowShareContentEditorWithContentName (int reqId, PlatformType platform, string contentName, Hashtable customFields)
  154. {
  155. Debug.Log("#WARING : Do not support this feature in Android temporarily" );
  156. }
  157. }
  158. #endif
  159. }