AndroidImpl.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. if (ssdk != null)
  95. {
  96. ssdk.Call("onekeyShare", reqID, (int)platform, content.GetShareParamsStr());
  97. }
  98. }
  99. public override void GetFriendList (int reqID, PlatformType platform, int count, int page)
  100. {
  101. Debug.Log("AndroidImpl ===>>> GetFriendList" );
  102. if (ssdk != null)
  103. {
  104. ssdk.Call("getFriendList", reqID, (int)platform, count, page);
  105. }
  106. }
  107. public override void AddFriend (int reqID, PlatformType platform, String account)
  108. {
  109. Debug.Log("AndroidImpl ===>>> FollowFriend" );
  110. if (ssdk != null)
  111. {
  112. ssdk.Call("followFriend", reqID, (int)platform, account);
  113. }
  114. }
  115. public override Hashtable GetAuthInfo (PlatformType platform)
  116. {
  117. Debug.Log("AndroidImpl ===>>> GetAuthInfo" );
  118. if (ssdk != null)
  119. {
  120. String result = ssdk.Call<String>("getAuthInfo", (int)platform);
  121. return (Hashtable)ShareMiniJSON.jsonDecode(result);
  122. }
  123. return new Hashtable ();
  124. }
  125. public override void DisableSSO (Boolean disable)
  126. {
  127. Debug.Log("AndroidImpl ===>>> DisableSSOWhenAuthorize" );
  128. if (ssdk != null)
  129. {
  130. ssdk.Call("disableSSOWhenAuthorize", disable);
  131. }
  132. }
  133. public override void ShareWithContentName (int reqId, PlatformType platform, string contentName, Hashtable customFields)
  134. {
  135. Debug.Log("#WARING : Do not support this feature in Android temporarily" );
  136. }
  137. public override void ShowPlatformListWithContentName (int reqId, string contentName, Hashtable customFields, PlatformType[] platforms, int x, int y)
  138. {
  139. Debug.Log("#WARING : Do not support this feature in Android temporarily" );
  140. }
  141. public override void ShowShareContentEditorWithContentName (int reqId, PlatformType platform, string contentName, Hashtable customFields)
  142. {
  143. Debug.Log("#WARING : Do not support this feature in Android temporarily" );
  144. }
  145. }
  146. #endif
  147. }