AndroidImpl.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. try{
  13. ssdk = new AndroidJavaObject("cn.sharesdk.unity3d.ShareSDKUtils", go.name, "_Callback");
  14. } catch(Exception e) {
  15. Console.WriteLine("{0} Exception caught.", e);
  16. }
  17. }
  18. public override void InitSDK (String appKey)
  19. {
  20. if (ssdk != null)
  21. {
  22. ssdk.Call("initSDK", appKey);
  23. }
  24. }
  25. public override void SetPlatformConfig (Hashtable configs)
  26. {
  27. String json = ShareMiniJSON.jsonEncode(configs);
  28. if (ssdk != null)
  29. {
  30. ssdk.Call("setPlatformConfig", json);
  31. }
  32. }
  33. public override void Authorize (int reqID, PlatformType platform)
  34. {
  35. Debug.Log("AndroidImpl ===>>> Authorize" );
  36. if (ssdk != null)
  37. {
  38. ssdk.Call("authorize", reqID, (int)platform);
  39. }
  40. }
  41. public override void CancelAuthorize (PlatformType platform)
  42. {
  43. if (ssdk != null)
  44. {
  45. ssdk.Call("removeAccount", (int)platform);
  46. }
  47. }
  48. public override bool IsAuthorized (PlatformType platform)
  49. {
  50. if (ssdk != null)
  51. {
  52. return ssdk.Call<bool>("isAuthValid", (int)platform);
  53. }
  54. return false;
  55. }
  56. public override bool IsClientValid (PlatformType platform)
  57. {
  58. if (ssdk != null)
  59. {
  60. return ssdk.Call<bool>("isClientValid", (int)platform);
  61. }
  62. return false;
  63. }
  64. public override void GetUserInfo (int reqID, PlatformType platform)
  65. {
  66. Debug.Log("AndroidImpl ===>>> ShowUser" );
  67. if (ssdk != null)
  68. {
  69. ssdk.Call("showUser", reqID, (int)platform);
  70. }
  71. }
  72. public override void ShareContent (int reqID, PlatformType platform, ShareContent content)
  73. {
  74. Debug.Log("AndroidImpl ===>>> ShareContent to one platform" );
  75. ShareContent (reqID, new PlatformType[]{ platform }, content);
  76. }
  77. public override void ShareContent (int reqID, PlatformType[] platforms, ShareContent content)
  78. {
  79. Debug.Log("AndroidImpl ===>>> Share" );
  80. if (ssdk != null)
  81. {
  82. foreach (PlatformType platform in platforms)
  83. {
  84. ssdk.Call("shareContent", reqID, (int)platform, content.GetShareParamsStr());
  85. }
  86. }
  87. }
  88. public override void ShowPlatformList (int reqID, PlatformType[] platforms, ShareContent content, int x, int y)
  89. {
  90. ShowShareContentEditor(reqID, 0, content);
  91. }
  92. public override void ShowShareContentEditor (int reqID, PlatformType platform, ShareContent content)
  93. {
  94. Debug.Log("AndroidImpl ===>>> OnekeyShare platform ===" + (int)platform );
  95. if (ssdk != null)
  96. {
  97. ssdk.Call("onekeyShare", reqID, (int)platform, content.GetShareParamsStr());
  98. }
  99. }
  100. public override void GetFriendList (int reqID, PlatformType platform, int count, int page)
  101. {
  102. Debug.Log("AndroidImpl ===>>> GetFriendList" );
  103. if (ssdk != null)
  104. {
  105. ssdk.Call("getFriendList", reqID, (int)platform, count, page);
  106. }
  107. }
  108. public override void AddFriend (int reqID, PlatformType platform, String account)
  109. {
  110. Debug.Log("AndroidImpl ===>>> FollowFriend" );
  111. if (ssdk != null)
  112. {
  113. ssdk.Call("followFriend", reqID, (int)platform, account);
  114. }
  115. }
  116. public override Hashtable GetAuthInfo (PlatformType platform)
  117. {
  118. Debug.Log("AndroidImpl ===>>> GetAuthInfo" );
  119. if (ssdk != null)
  120. {
  121. String result = ssdk.Call<String>("getAuthInfo", (int)platform);
  122. return (Hashtable)ShareMiniJSON.jsonDecode(result);
  123. }
  124. return new Hashtable ();
  125. }
  126. public override void DisableSSO (Boolean disable)
  127. {
  128. Debug.Log("AndroidImpl ===>>> DisableSSOWhenAuthorize" );
  129. if (ssdk != null)
  130. {
  131. ssdk.Call("disableSSOWhenAuthorize", disable);
  132. }
  133. }
  134. public override void ShareWithContentName (int reqId, PlatformType platform, string contentName, Hashtable customFields)
  135. {
  136. Debug.Log("#WARING : Do not support this feature in Android temporarily" );
  137. }
  138. public override void ShowPlatformListWithContentName (int reqId, string contentName, Hashtable customFields, PlatformType[] platforms, int x, int y)
  139. {
  140. Debug.Log("#WARING : Do not support this feature in Android temporarily" );
  141. }
  142. public override void ShowShareContentEditorWithContentName (int reqId, PlatformType platform, string contentName, Hashtable customFields)
  143. {
  144. Debug.Log("#WARING : Do not support this feature in Android temporarily" );
  145. }
  146. }
  147. #endif
  148. }