android.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // pages/android/android.js
  2. const {
  3. miniAppPluginId
  4. } = require('../../constant');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. myPlugin: undefined
  11. },
  12. onLoad(option) {
  13. wx.miniapp.loadNativePlugin({
  14. pluginId: miniAppPluginId,
  15. success: (plugin) => {
  16. console.log('load plugin success', plugin)
  17. this.setData({
  18. myPlugin: plugin
  19. })
  20. },
  21. fail: (e) => {
  22. console.log('load plugin fail', e)
  23. }
  24. })
  25. },
  26. onLoadPlugin() {
  27. this.data.myPlugin.initPlugin(({
  28. 'channelCode': '9999'
  29. }), (res) => {
  30. if (res === "success") {
  31. console.log("初始化plugin成功")
  32. } else {
  33. console.log("初始化plugin失败")
  34. }
  35. })
  36. },
  37. onInitPermission() {
  38. let permissionArr =
  39. "android.permission.INTERNET" + "," +
  40. "android.permission.ACCESS_NETWORK_STATE" + "," +
  41. "android.permission.ACCESS_WIFI_STATE" + "," +
  42. "android.permission.RECORD_AUDIO" + "," +
  43. "android.permission.READ_EXTERNAL_STORAGE" + "," +
  44. "android.permission.WRITE_EXTERNAL_STORAGE" + "," +
  45. "android.permission.READ_PHONE_STATE"
  46. this.data.myPlugin.initPermissions(({
  47. 'permissionArr': permissionArr
  48. }), (res) => {
  49. res = JSON.parse(res);
  50. console.log("res:" + res)
  51. console.log("res:" + res.result)
  52. if (res.result === "success") {
  53. console.log("初始化权限成功")
  54. } else {
  55. console.log("初始化权限失败")
  56. }
  57. })
  58. },
  59. checkRecordAudioPermission() {
  60. var test = this.data.myPlugin.checkPermission({
  61. 'permission': 'android.permission.RECORD_AUDIO'
  62. })
  63. console.log("是否有权限:" + test)
  64. },
  65. getDeviceUUID() {
  66. var device_uuid = this.data.myPlugin.getDeviceUuid({})
  67. console.log("获取的uuid:" + device_uuid)
  68. },
  69. getAndroidSN() {
  70. var sn = this.data.myPlugin.AndroidSN({})
  71. console.log("获取的SN:" + sn)
  72. },
  73. initUmengSDK() {
  74. this.data.myPlugin.initUmengSDK(({
  75. 'channelCode': '3016'
  76. }), (res) => {
  77. if (res === "success") {
  78. console.log("初始化成功")
  79. } else {
  80. console.log("初始化失败")
  81. }
  82. })
  83. },
  84. })