ReflectionAndroid.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. // Created by Hulimin 2018-11-05
  2. // Native function called by javascript
  3. var Global = require("Global");
  4. var BaseDefine = require("BaseDefine");
  5. var popScence = require("popScence");
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. },
  10. statics: {
  11. changeOrientation: function (orientation) {
  12. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "changeOrientation", "(Ljava/lang/String;)V", orientation);
  13. },
  14. getAppId: function () {
  15. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getAppId", "()Ljava/lang/String;") || "";
  16. },
  17. getAndroidVersionCode: function () {
  18. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getVersionCode", "()I") || 0;
  19. },
  20. getNetState: function () {
  21. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getNetState", "()I");
  22. },
  23. getSignalLevel: function () {
  24. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getSignalLevel", "()I");
  25. },
  26. getBatterylevel: function () {
  27. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getBatterylevel", "()I");
  28. },
  29. pasteboard: function (str) {
  30. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "pasteboard", "(Ljava/lang/String;)V", str);
  31. },
  32. getPasteBoardString: function () {
  33. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getPasteBoardString", "()Ljava/lang/String;");
  34. },
  35. updatePackage: function (url) {
  36. url = BaseDefine.SHARE_URL + "?Channel=" + cc.vv.config.Channel + "&ChannelIdx=" + cc.vv.config.ChannelIdx;
  37. cc.sys.openURL(url);
  38. },
  39. // 获取设备唯一标识码(UUID)
  40. getDeviceUUID: function () {
  41. Global.print("jsb.reflection.callStaticMethod: getDeviceUUID");
  42. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getDeviceUUID", "()Ljava/lang/String;");
  43. },
  44. // faceBook登录
  45. loginFaceBook: function () {
  46. Global.print("jsb.reflection.callStaticMethod: LoginFb");
  47. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "LoginFb", "()V");
  48. },
  49. shareUrlToFaceBook: function (url) {
  50. url = url || "";
  51. Global.print("jsb.reflection.callStaticMethod: shareUrlToFaceBook");
  52. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "shareUrlToFaceBook", "(Ljava/lang/String;)V", url);
  53. },
  54. sharePhotoToFaceBook: function (path) {
  55. if (!path) { return }
  56. Global.print("jsb.reflection.callStaticMethod: sharePhotoToFaceBook");
  57. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "sharePhotoToFaceBook", "(Ljava/lang/String;)V", path);
  58. },
  59. shareVideoToFaceBook: function (url) {
  60. if (!url) { return }
  61. Global.print("jsb.reflection.callStaticMethod: shareVideoToFaceBook");
  62. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "shareVideoToFaceBook", "(Ljava/lang/String;)V", url);
  63. },
  64. shareUrlToFaceBookMessenger: function (title, url) {
  65. Global.print("jsb.reflection.callStaticMethod: shareUrlToFaceBookMessenger");
  66. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "shareUrlToFaceBookMessenger", "(Ljava/lang/String;Ljava/lang/String;)V", title, url);
  67. },
  68. /**
  69. * facebook Analytics 埋点数据
  70. * @param {String} name 事件名称
  71. * @param {double} value 事件总值(可选)
  72. * @param {JSON} param 事件参数(可选),成员类型 Int、Double、Boolean、String,默认String,例:{'age': 10, 'from': 'yn'}
  73. */
  74. FBCustomLogEvent: function (name, value, param) {
  75. Global.print("jsb.reflection.callStaticMethod: FBCustomLogEvent");
  76. if (!name) {
  77. return;
  78. }
  79. if (!(typeof value == 'number') && !param) {
  80. param = value;
  81. value = 0;
  82. }
  83. value = value | 0;
  84. param = (param) ? param : {};
  85. param = JSON.stringify(param);
  86. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "FBCustomLogEvent", "(Ljava/lang/String;FLjava/lang/String;)V", name, value, param);
  87. },
  88. /**
  89. * Adjust 访问用户当前的归因信息
  90. */
  91. getAdjustAttribution: function () {
  92. Global.print("jsb.reflection.callStaticMethod: getAdjustAttribution");
  93. let param = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getAdjustAttribution", "()Ljava/lang/String;");
  94. window.setAdjustAttribution(param);
  95. },
  96. /**
  97. * Adjust 获取Adjust的AdID
  98. */
  99. getAdjustAdID: function () {
  100. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getAdjustAdID", "()Ljava/lang/String;");
  101. },
  102. /**
  103. * 发送Adjust 的跟踪事件
  104. * @param {String} eventJSON 发送跟踪事件需要的JSON结构体
  105. */
  106. trackAdjustEvent(json) {
  107. if (json) {
  108. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "trackAdjustEvent", "(Ljava/lang/String;)Z", json);
  109. }
  110. return false;
  111. },
  112. getDeviceInfo(param) {
  113. let result = null;
  114. if (param) {
  115. result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getDeviceInfo", "(Ljava/lang/String;)Ljava/lang/String;", param);
  116. } else {
  117. result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getDeviceInfo", "()Ljava/lang/String;");
  118. }
  119. return JSON.parse(result);
  120. },
  121. getSensorInfo(param) {
  122. let result = null;
  123. if (param) {
  124. result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getSensorInfo", "(Ljava/lang/String;)Ljava/lang/String;", param);
  125. } else {
  126. result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getSensorInfo", "()Ljava/lang/String;");
  127. }
  128. return JSON.parse(result);
  129. },
  130. getServerInfo(param) {
  131. let result = null;
  132. if (param) {
  133. result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getServerInfo", "(Ljava/lang/String;)Ljava/lang/String;", param);
  134. } else {
  135. result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getServerInfo", "()Ljava/lang/String;");
  136. }
  137. return JSON.parse(result);
  138. },
  139. getGoogleAAID() {
  140. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getGoogleAAID", "()Ljava/lang/String;");
  141. },
  142. getSIMInfo(param) {
  143. let result = null;
  144. if (param) {
  145. result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getSIMInfo", "(Ljava/lang/String;)Ljava/lang/String;", param);
  146. } else {
  147. result = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getSIMInfo", "()Ljava/lang/String;");
  148. }
  149. return JSON.parse(result);
  150. },
  151. /************AppsFlyer */
  152. /** 初始化并启动AppsFlyer */
  153. initAppsFlyer(key = "", jsCallBack = "", jsErrorCallBack = "") {
  154. jsb.reflection.callStaticMethod(
  155. "org/cocos2dx/javascript/AppsFlyerNative",
  156. "initAppsFlyer",
  157. "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
  158. key,
  159. jsCallBack,
  160. jsErrorCallBack);
  161. },
  162. /** 获取本地的归因数据 */
  163. appsFlyerGetConversionData() {
  164. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "getConversionData", "()Ljava/lang/String;");
  165. },
  166. /** 设置全局的货币Code */
  167. appsFlyerSetCurrencyCode(code = "") {
  168. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setCurrencyCode", "(Ljava/lang/String;)V", code);
  169. },
  170. /** 发送AppsFlyer事件 */
  171. appsFlyerLogEvent(eventType, param = JSON.stringify(""), jsCallBack = "", jsErrorCallBack = "") {
  172. if (!eventType) {
  173. return;
  174. }
  175. jsb.reflection.callStaticMethod(
  176. "org/cocos2dx/javascript/AppsFlyerNative",
  177. "logEvent",
  178. "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
  179. eventType,
  180. param,
  181. jsCallBack,
  182. jsErrorCallBack);
  183. },
  184. /** 获取AppsFlyer的唯一标识 */
  185. appsFlyerGetAppsFlyerID() {
  186. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "getAppsFlyerID", "()Ljava/lang/String;");
  187. },
  188. /** 设置自定义玩家ID */
  189. appsFlyerSetCustomerUserID(id = "") {
  190. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setCustomerUserID", "(Ljava/lang/String;)V", id);
  191. },
  192. /** 获取自定义玩家ID */
  193. appsFlyerGetCustomerUserID() {
  194. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "getCustomerUserID", "()Ljava/lang/String;");
  195. },
  196. /** 设置应用绑定的OnceLinK模板密钥 */
  197. appsFlyerSetAppInviteOnceLink(id = "") {
  198. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setAppInviteOnceLink", "(Ljava/lang/String;)V", id);
  199. },
  200. /** 初始化链接生成器 */
  201. appsFlyerInitShareLinkGenerator(channel) {
  202. if (!channel) { return; }
  203. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "initShareLinkGenerator", "(Ljava/lang/String;)V", channel);
  204. },
  205. /** 设置链接生成器的渠道参数 */
  206. appsFlyerSetCampaignOnShareLinkGenerator(campaign) {
  207. if (!campaign) { return; }
  208. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setCampaignOnShareLinkGenerator", "(Ljava/lang/String;)V", campaign);
  209. },
  210. /** 设置链接生成器的分享者名称参数 */
  211. appsFlyerSetReferrerNameOnShareLinkGenerator(name) {
  212. if (!name) { return; }
  213. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setReferrerNameOnShareLinkGenerator", "(Ljava/lang/String;)V", name);
  214. },
  215. /** 设置链接生成器的链接展示图像URL参数 */
  216. appsFlyerSetReferrerImageURLOnShareLinkGenerator(url) {
  217. if (!url) { return; }
  218. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setReferrerImageURLOnShareLinkGenerator", "(Ljava/lang/String;)V", url);
  219. },
  220. /** 设置链接生成器的分享者用户ID参数 */
  221. appsFlyerSetReferrerCustomerIdOnShareLinkGenerator(id) {
  222. if (!id) { return; }
  223. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setReferrerCustomerIdOnShareLinkGenerator", "(Ljava/lang/String;)V", id.toString());
  224. },
  225. /** 设置链接生成器的自定义参数 */
  226. appsFlyerAddParameterOnShareLinkGenerator(key, value = "") {
  227. if (!key) { return; }
  228. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "addParameterOnShareLinkGenerator", "(Ljava/lang/String;Ljava/lang/String;)V", key, value);
  229. },
  230. appsFlyerAddParametersOnShareLinkGenerator(json) {
  231. if (!json) { return; }
  232. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "addParametersOnShareLinkGenerator", "(Ljava/lang/String;)V", json);
  233. },
  234. /** 设置链接生成器的品牌参数 */
  235. appsFlyerSetBrandDomainOnShareLinkGenerator(domain) {
  236. if (!domain) { return; }
  237. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "setBrandDomainOnShareLinkGenerator", "(Ljava/lang/String;)V", domain);
  238. },
  239. /** 开始生成链接 */
  240. appsFlyerGenerateLink(successCallBack = "", errorCallBack = "") {
  241. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppsFlyerNative", "generateLink", "(Ljava/lang/String;Ljava/lang/String;)V", successCallBack, errorCallBack);
  242. },
  243. /************ */
  244. /** 本地支付接口 */
  245. payByPaytm(midId = "", orderId = "", txnTokenId = "", txnAmountId = "", callBackUrl = "", jsCallBack = "") {
  246. if (!!midId && !!orderId && !!txnTokenId && !!txnAmountId && !!callBackUrl) {
  247. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "payByPaytm",
  248. "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
  249. midId,
  250. orderId,
  251. txnTokenId,
  252. txnAmountId,
  253. callBackUrl,
  254. jsCallBack
  255. );
  256. }
  257. },
  258. shake(time) {
  259. Global.print("shake")
  260. if (cc.vv.audioMgr.shakeOpen == 1) {
  261. Global.print("start shake")
  262. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "shake", "(I)V", time);
  263. }
  264. },
  265. isVPNUsed() {
  266. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "isVPNUsed", "()Z");
  267. },
  268. getGameMode() {
  269. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getGameMode", "()I") | 0;
  270. },
  271. //google支付
  272. doBuy(productID, orderID) {
  273. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "doBuy", "(Ljava/lang/String;Ljava/lang/String;)V", productID, orderID);
  274. },
  275. checkBuy() {
  276. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "checkBuy", "()V");
  277. },
  278. buySuccess(token) {
  279. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "buySuccess", "(Ljava/lang/String;)V", token);
  280. },
  281. /** OpenInstall */
  282. reportRegister() {
  283. Global.print("openinstall::reportRegister")
  284. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "reportRegister", "()V");
  285. },
  286. reportEffectPoint(effect_key, effect_value) {
  287. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "reportEffectPoint", "(Ljava/lang/String;I)V", effect_key, effect_value);
  288. },
  289. /** FireBase */
  290. FireBaseLogEvent(effect_key, effect_value) {
  291. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "FireBaseLogEvent", "(Ljava/lang/String;Ljava/lang/String;)V", effect_key, effect_value);
  292. },
  293. // //初始化子游戏的资源到本地缓存
  294. // initSubGameOnCache(bundleName) {
  295. // jsb.reflection.callStaticMethod("org/cocos2dx/javascript/CopyFileUtil", "initDownloadSubPackGame", "(Ljava/lang/String;)V", bundleName);
  296. // },
  297. //刷新子游戏manifest文件在下载后
  298. refreshManifestOnDownloaded(bundleName) {
  299. let appPackName = cc.vv.reflection.getAppId();
  300. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/CopyFileUtil", "copyFile", "(Ljava/lang/String;Ljava/lang/String;Z)V",
  301. "/data/user/0/" + appPackName + "/files/blackjack-remote-asset/assets/" + bundleName + "/project.manifest",
  302. "/data/user/0/" + appPackName + "/files/manifest/" + bundleName + "_project.manifest",
  303. false
  304. );
  305. },
  306. getGoogleReferrer() {
  307. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getGoogleReferrer", "()Ljava/lang/String;");
  308. },
  309. }
  310. });