AndroidImpl.cs 4.5 KB

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