Browse Source

优化android端代码及uni端

module-tcpserver-mqtt-t4j-faceSDK
zmt 3 years ago
parent
commit
e534c86dee
  1. 1
      .gitignore
  2. 4
      app/src/main/assets/apps/__UNI__2B9497D/www/app-config-service.js
  3. 2
      app/src/main/assets/apps/__UNI__2B9497D/www/app-service.js
  4. 2
      app/src/main/assets/apps/__UNI__2B9497D/www/app-view.js
  5. 2
      app/src/main/assets/apps/__UNI__2B9497D/www/manifest.json
  6. 2
      app/src/main/assets/apps/__UNI__2B9497D/www/pages/index/scan.js
  7. 2
      app/src/main/assets/apps/__UNI__2B9497D/www/pages/sample/ext-component.js
  8. 2
      app/src/main/assets/apps/__UNI__2B9497D/www/pages/sample/ext-module.js
  9. 2
      build.gradle
  10. 2
      face_module/src/main/java/com/appdev/face_module/MyManager.java
  11. 1
      gradle.properties
  12. 3
      uniapp示例工程源码/unipluginDemo/manifest.json
  13. 12
      uniapp示例工程源码/unipluginDemo/pages.json
  14. 2
      uniapp示例工程源码/unipluginDemo/pages/index/index.vue
  15. 215
      uniapp示例工程源码/unipluginDemo/pages/sample/ext-module-vue.vue
  16. 48
      uniapp示例工程源码/unipluginDemo/pages/sample/ext-module.nvue
  17. 4
      uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/app-config-service.js
  18. 2
      uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/app-service.js
  19. 2
      uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/app-view.js
  20. 2
      uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/manifest.json
  21. 2
      uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/pages/index/scan.js
  22. 2
      uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/pages/sample/ext-component.js
  23. 2
      uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/pages/sample/ext-module.js
  24. 4
      uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/app-config-service.js
  25. 2
      uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/app-service.js
  26. 2
      uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/app-view.js
  27. 2
      uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/manifest.json
  28. 2
      uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/pages/index/scan.js
  29. 2
      uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/pages/sample/ext-component.js
  30. 2
      uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/pages/sample/ext-module.js
  31. 70
      uniapp示例工程源码/unipluginDemo/utils/timeFormat.js
  32. 56
      zmt_module/src/main/java/io/dcloud/zmt_module/AsyncTask.java
  33. 62
      zmt_module/src/main/java/io/dcloud/zmt_module/PermissionCheck.java
  34. 3
      zmt_module/src/main/java/io/dcloud/zmt_module/TcpServer.java
  35. 112
      zmt_module/src/main/java/io/dcloud/zmt_module/zmtClass.java

1
.gitignore

@ -11,3 +11,4 @@
.externalNativeBuild
app/build
uniapp\347\244\272\344\276\213\345\267\245\347\250\213\346\272\220\347\240\201/unipluginDemo/unpackage

4
app/src/main/assets/apps/__UNI__2B9497D/www/app-config-service.js

@ -1,8 +1,8 @@
var isReady=false;var onReadyCallbacks=[];
var isServiceReady=false;var onServiceReadyCallbacks=[];
var __uniConfig = {"pages":["pages/index/index","pages/index/ball_list","pages/index/scan","pages/sample/ext-module","pages/sample/ext-component","pages/sample/richAlert"],"window":{"navigationBarTextStyle":"black","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#F8F8F8","backgroundColor":"#F8F8F8"},"nvueCompiler":"uni-app","nvueStyleCompiler":"weex","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"unipluginDemo","compilerVersion":"3.3.11","entryPagePath":"pages/index/index","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
var __uniRoutes = [{"path":"/pages/index/index","meta":{"isQuit":true},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/ball_list","meta":{},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/scan","meta":{"isNVue":true},"window":{"navigationBarTitleText":"22222"}},{"path":"/pages/sample/ext-module","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 module"}},{"path":"/pages/sample/ext-component","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 component"}},{"path":"/pages/sample/richAlert","meta":{},"window":{"navigationBarTitleText":"RichAlert"}}];
var __uniConfig = {"pages":["pages/sample/ext-module-vue","pages/index/index","pages/index/ball_list","pages/index/scan","pages/sample/ext-module","pages/sample/ext-component","pages/sample/richAlert"],"window":{"navigationBarTextStyle":"black","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#F8F8F8","backgroundColor":"#F8F8F8"},"nvueCompiler":"uni-app","nvueStyleCompiler":"weex","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"unipluginDemo","compilerVersion":"3.3.11","entryPagePath":"pages/sample/ext-module-vue","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
var __uniRoutes = [{"path":"/pages/sample/ext-module-vue","meta":{"isQuit":true},"window":{"navigationBarTitleText":"扩展 module vue"}},{"path":"/pages/index/index","meta":{},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/ball_list","meta":{},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/scan","meta":{"isNVue":true},"window":{"navigationBarTitleText":"22222"}},{"path":"/pages/sample/ext-module","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 module nvue"}},{"path":"/pages/sample/ext-component","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 component"}},{"path":"/pages/sample/richAlert","meta":{},"window":{"navigationBarTitleText":"RichAlert"}}];
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,global:void 0,window:void 0,document:void 0,frames:void 0,self:void 0,location:void 0,navigator:void 0,localStorage:void 0,history:void 0,Caches:void 0,screen:void 0,alert:void 0,confirm:void 0,prompt:void 0,fetch:void 0,XMLHttpRequest:void 0,WebSocket:void 0,webkit:void 0,print:void 0}}}});

2
app/src/main/assets/apps/__UNI__2B9497D/www/app-service.js
File diff suppressed because it is too large
View File

2
app/src/main/assets/apps/__UNI__2B9497D/www/app-view.js
File diff suppressed because it is too large
View File

2
app/src/main/assets/apps/__UNI__2B9497D/www/manifest.json

@ -1 +1 @@
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__2B9497D","name":"unipluginDemo","version":{"name":"1.0.0","code":"100"},"description":"","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"usingComponents":true,"nvueCompiler":"uni-app","compilerVersion":3,"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"3.3.11","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html"}}
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__2B9497D","name":"unipluginDemo","version":{"name":"1.0.0","code":"100"},"description":"","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"compatible":{"ignoreVersion":true},"usingComponents":true,"nvueCompiler":"uni-app","compilerVersion":3,"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"3.3.11","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html"}}

2
app/src/main/assets/apps/__UNI__2B9497D/www/pages/index/scan.js
File diff suppressed because it is too large
View File

2
app/src/main/assets/apps/__UNI__2B9497D/www/pages/sample/ext-component.js
File diff suppressed because it is too large
View File

2
app/src/main/assets/apps/__UNI__2B9497D/www/pages/sample/ext-module.js
File diff suppressed because it is too large
View File

2
build.gradle

@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()

2
face_module/src/main/java/com/appdev/face_module/MyManager.java

@ -40,7 +40,7 @@ public class MyManager {
System.out.println(TAG+"initSDK");
faceAuth = new FaceAuth();
System.out.println(TAG+"FaceAuth");
System.out.println(TAG+"FaceAuth Device ID:"+faceAuth.getDeviceId(mContext));
// boolean isConfigExit = GateConfigUtils.isConfigExit();
// boolean isInitConfig = GateConfigUtils.initConfig();

1
gradle.properties

@ -10,6 +10,7 @@ android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
android.useDeprecatedNdk=true
#startParameter.offline = false
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects

3
uniapp示例工程源码/unipluginDemo/manifest.json

@ -7,6 +7,9 @@
"transformPx" : false,
/* 5+App */
"app-plus" : {
"compatible":{
"ignoreVersion":true //true,
},
"usingComponents" : true,
"nvueCompiler" : "uni-app",
"compilerVersion" : 3,

12
uniapp示例工程源码/unipluginDemo/pages.json

@ -1,6 +1,11 @@
{
"pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages
{
"path": "pages/sample/ext-module-vue",
"style": {
"navigationBarTitleText": "扩展 module vue"
}
},
{
"path": "pages/index/index",
"style": {
@ -22,9 +27,10 @@
{
"path": "pages/sample/ext-module",
"style": {
"navigationBarTitleText": "扩展 module"
"navigationBarTitleText": "扩展 module nvue"
}
},
},
{
"path": "pages/sample/ext-component",
"style": {

2
uniapp示例工程源码/unipluginDemo/pages/index/index.vue

@ -33,7 +33,7 @@
id: 'ext-module',
name: '扩展 module测试列表',
open: false,
url: '/pages/sample/ext-module'
url: '/pages/sample/ext-module-vue'
},
{
id: 'ext-component',

215
uniapp示例工程源码/unipluginDemo/pages/sample/ext-module-vue.vue

@ -0,0 +1,215 @@
<template>
<div class="content">
<button class="btn" type="primary" @click="gotoNativePage">跳转原生Activity</button>
<button class="btn" type="primary" @click="tcpAsyncFunc">[开启TcpServer]</button>
<text class="tips">
点击后将开启TcpServer. 本机IP: 192.168.1.64 端口16666
</text>
<!-- <button type="primary" @click="testFun2">zmt-testFun2</button> -->
<button class="btn" type="primary" @click="faceAsyncFunc">[百度人脸SDK授权]</button>
<text class="tips">
点击后将进行百度人脸SDK初始化及授权申请,该授权码写死在Android端zmt_module内faceClass,因已使用过,将返回已被占用提示.
</text>
<view class="console">
<text class="log" v-for="i in logs">{{i}}</text>
</view>
<button class="btn" type="primary" @click="testAsyncFunc2">uniplugin_module_ox testAsyncFunc2</button>
<button class="btn" type="primary" @click="testSyncFunc2">uniplugin_module_ox testSyncFunc2</button>
<button class="btn" type="primary" @click="testAsyncFunc">uniplugin_module testAsyncFunc</button>
<button class="btn" type="primary" @click="testSyncFunc">uniplugin_module testSyncFunc</button>
</div>
</template>
<script>
// #ifdef APP-PLUS
// module
var zmtModule = uni.requireNativePlugin("Zmt-Module")
var testModule = uni.requireNativePlugin("TestModule") //uniplugin_module
var uniplugin_module_ox = uni.requireNativePlugin("uniplugin_module_ox") //uniplugin_module_ox
var faceModule = uni.requireNativePlugin("Face-Module") //SDK, face_module
const modal = uni.requireNativePlugin('modal');
// #endif
import {timeFormat} from "../../utils/timeFormat.js"
export default {
onLoad() {
this.initAPPListener()
},
onReady() {
this.logs.push("当前时间:"+this.getTime())
},
data() {
return {
logs:["LOG VIEW"]
}
},
methods: {
initAPPListener(){
// #ifdef APP-PLUS
let that = this
// ,
plus.globalEvent.addEventListener('myEvent', function(e){
modal.toast({
message: "TestEvent收到:"+JSON.stringify(e),
duration: 3.5
});
that.log("全局事件接收:"+JSON.stringify(e))
});
// #endif
},
//SDK,,(android faceClass)
faceAsyncFunc() {
this.log("执行faceModule.faceAsyncFunc");
//
faceModule.faceAsyncFunc({
'name': 'unimp',
'age': 1
},
(ret) => {
modal.toast({
message: ret,
duration: 1.5
});
this.log(JSON.stringify(ret))
})
},
tcpAsyncFunc(){
//
this.log("Click Tcp Server.")
zmtModule.tcpAsyncFunc({
'port':"16666",
},
(ret) => {
modal.toast({
message: ret,
duration: 2
});
this.log("invoke:"+JSON.stringify(ret))
})
},
testFun2(){
//
var ret = zmtModule.testSyncFunc({
'name': 'unimp',
'age': 1
})
modal.toast({
message: ret,
duration: 1.5
});
},
testAsyncFunc() {
//
testModule.testAsyncFunc({
'name': 'unimp',
'age': 1
},
(ret) => {
modal.toast({
message: ret,
duration: 1.5
});
})
},
testSyncFunc() {
//
var ret = testModule.testSyncFunc({
'name': 'unimp',
'age': 1
})
modal.toast({
message: ret,
duration: 1.5
});
},
testAsyncFunc2() {
//
uniplugin_module_ox.testAsyncFunc2({
'name': 'unimp',
'age': 1
},
(ret) => {
modal.toast({
message: ret,
duration: 1.5
});
})
},
testSyncFunc2() {
//
var ret = uniplugin_module_ox.testSyncFunc2({
'name': 'unimp',
'age': 1
})
modal.toast({
message: ret,
duration: 1.5
});
},
//Log Viewtxt
log(txt){
this.logs.push(this.getTime()+` ${txt}`)
},
//
getTime(){
return timeFormat(new Date(),'mm/dd hh:MM:ss')
},
gotoNativePage() {
testModule.gotoNativePage();
}
}
}
</script>
<style lang="scss">
.content{
// width: 750rpx;
// margin-top: 10rpx;
// display: flex;
// flex-wrap: nowrap;
// align-items: flex-start;
// flex-direction: column;
// justify-content: center;
font-size: 12px;
}
// button{
// margin-top: 3px;
// }
.btn{
margin: 3px;
// width: 95%;
}
.tips{
font-size: 11px;
color: gray;
font-weight: 800;
}
.console{
// margin-left: 25rpx;
// width: %;
// height: auto;
display: flex;
flex-wrap: nowrap;
flex-direction: column;
align-items: flex-start;
background-color: lightgray;
padding: 20rpx;
}
.log{
color: darkred;
font-size: 11px;
font-weight: 800;
}
</style>

48
uniapp示例工程源码/unipluginDemo/pages/sample/ext-module.nvue

@ -14,6 +14,9 @@
点击后将进行百度人脸SDK初始化及授权申请,该授权码写死在Android端zmt_module内faceClass,因已使用过,将返回已被占用提示.
</text>
<view class="console">
<text class="log" v-for="i in logs">{{i}}</text>
</view>
<button class="btn" type="primary" @click="testAsyncFunc2">uniplugin_module_ox testAsyncFunc2</button>
<button class="btn" type="primary" @click="testSyncFunc2">uniplugin_module_ox testSyncFunc2</button>
<button class="btn" type="primary" @click="testAsyncFunc">uniplugin_module testAsyncFunc</button>
@ -32,9 +35,21 @@
const modal = uni.requireNativePlugin('modal');
// #endif
import {timeFormat} from "../../utils/timeFormat.js"
export default {
onLoad() {
this.initAPPListener()
this.initAPPListener()
},
onReady() {
this.logs.push("当前时间:"+this.getTime())
},
data() {
return {
logs:["LOG VIEW"]
}
},
methods: {
@ -51,7 +66,7 @@
},
//百度人脸SDK,初始化,并申请授权(授权码写死在android端 faceClass)
faceAsyncFunc() {
console.log("测试开始faceAsyncFunc");
this.log("执行faceModule.faceAsyncFunc");
// 调用异步方法
faceModule.faceAsyncFunc({
'name': 'unimp',
@ -62,10 +77,12 @@
message: ret,
duration: 1.5
});
this.log(JSON.stringify(ret))
})
},
tcpAsyncFunc(){
// 调用异步方法
this.log("开启Tcp Server.")
zmtModule.tcpAsyncFunc({
'name': 'unimp',
'age': 1
@ -73,8 +90,10 @@
(ret) => {
modal.toast({
message: ret,
duration: 1.5
duration: 2
});
// this.logs.push(this.getTime()+" tcp接收:"+ret.code)
this.log("tcp接收:"+ret.code)
})
},
testFun2(){
@ -137,6 +156,14 @@
duration: 1.5
});
},
//在Log View打印txt
log(txt){
this.logs.push(this.getTime()+` ${txt}`)
},
//返回当前时间
getTime(){
return timeFormat(new Date(),'mm/dd hh:MM:ss')
},
gotoNativePage() {
testModule.gotoNativePage();
}
@ -144,6 +171,7 @@
}
</script>
<style lang="scss">
.content{
// width: 750rpx;
// margin-top: 10rpx;
@ -152,6 +180,7 @@
// align-items: flex-start;
// flex-direction: column;
// justify-content: center;
font-size: 12px;
}
// button{
@ -166,4 +195,17 @@
color: gray;
font-weight: 800;
}
.console{
// margin-left: 25rpx;
// width: %;
// height: auto;
background-color: lightgray;
padding: 20rpx;
}
.log{
color: darkred;
font-size: 11px;
font-weight: 800;
}
</style>

4
uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/app-config-service.js

@ -1,8 +1,8 @@
var isReady=false;var onReadyCallbacks=[];
var isServiceReady=false;var onServiceReadyCallbacks=[];
var __uniConfig = {"pages":["pages/index/index","pages/index/ball_list","pages/index/scan","pages/sample/ext-module","pages/sample/ext-component","pages/sample/richAlert"],"window":{"navigationBarTextStyle":"black","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#F8F8F8","backgroundColor":"#F8F8F8"},"nvueCompiler":"uni-app","nvueStyleCompiler":"weex","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"unipluginDemo","compilerVersion":"3.3.11","entryPagePath":"pages/index/index","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
var __uniRoutes = [{"path":"/pages/index/index","meta":{"isQuit":true},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/ball_list","meta":{},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/scan","meta":{"isNVue":true},"window":{"navigationBarTitleText":"22222"}},{"path":"/pages/sample/ext-module","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 module"}},{"path":"/pages/sample/ext-component","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 component"}},{"path":"/pages/sample/richAlert","meta":{},"window":{"navigationBarTitleText":"RichAlert"}}];
var __uniConfig = {"pages":["pages/sample/ext-module-vue","pages/index/index","pages/index/ball_list","pages/index/scan","pages/sample/ext-module","pages/sample/ext-component","pages/sample/richAlert"],"window":{"navigationBarTextStyle":"black","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#F8F8F8","backgroundColor":"#F8F8F8"},"nvueCompiler":"uni-app","nvueStyleCompiler":"weex","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"unipluginDemo","compilerVersion":"3.3.11","entryPagePath":"pages/sample/ext-module-vue","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
var __uniRoutes = [{"path":"/pages/sample/ext-module-vue","meta":{"isQuit":true},"window":{"navigationBarTitleText":"扩展 module vue"}},{"path":"/pages/index/index","meta":{},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/ball_list","meta":{},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/scan","meta":{"isNVue":true},"window":{"navigationBarTitleText":"22222"}},{"path":"/pages/sample/ext-module","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 module nvue"}},{"path":"/pages/sample/ext-component","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 component"}},{"path":"/pages/sample/richAlert","meta":{},"window":{"navigationBarTitleText":"RichAlert"}}];
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,global:void 0,window:void 0,document:void 0,frames:void 0,self:void 0,location:void 0,navigator:void 0,localStorage:void 0,history:void 0,Caches:void 0,screen:void 0,alert:void 0,confirm:void 0,prompt:void 0,fetch:void 0,XMLHttpRequest:void 0,WebSocket:void 0,webkit:void 0,print:void 0}}}});

2
uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/app-service.js
File diff suppressed because it is too large
View File

2
uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/app-view.js
File diff suppressed because it is too large
View File

2
uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/manifest.json

@ -1 +1 @@
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__2B9497D","name":"unipluginDemo","version":{"name":"1.0.0","code":"100"},"description":"","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"usingComponents":true,"nvueCompiler":"uni-app","compilerVersion":3,"distribute":{"google":{"permissions":["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>","<uses-permission android:name=\"android.permission.READ_CONTACTS\"/>","<uses-permission android:name=\"android.permission.VIBRATE\"/>","<uses-permission android:name=\"android.permission.READ_LOGS\"/>","<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>","<uses-feature android:name=\"android.hardware.camera.autofocus\"/>","<uses-permission android:name=\"android.permission.WRITE_CONTACTS\"/>","<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.CAMERA\"/>","<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>","<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>","<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>","<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>","<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>","<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>","<uses-permission android:name=\"android.permission.CALL_PHONE\"/>","<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>","<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>","<uses-feature android:name=\"android.hardware.camera\"/>","<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>","<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"]},"apple":{},"plugins":{"audio":{"mp3":{"description":"Android平台录音支持MP3格式文件"}}}},"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"3.3.11","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html"}}
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__2B9497D","name":"unipluginDemo","version":{"name":"1.0.0","code":"100"},"description":"","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"compatible":{"ignoreVersion":true},"usingComponents":true,"nvueCompiler":"uni-app","compilerVersion":3,"distribute":{"google":{"permissions":["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>","<uses-permission android:name=\"android.permission.READ_CONTACTS\"/>","<uses-permission android:name=\"android.permission.VIBRATE\"/>","<uses-permission android:name=\"android.permission.READ_LOGS\"/>","<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>","<uses-feature android:name=\"android.hardware.camera.autofocus\"/>","<uses-permission android:name=\"android.permission.WRITE_CONTACTS\"/>","<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.CAMERA\"/>","<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>","<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>","<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>","<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>","<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>","<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>","<uses-permission android:name=\"android.permission.CALL_PHONE\"/>","<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>","<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>","<uses-feature android:name=\"android.hardware.camera\"/>","<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>","<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"]},"apple":{},"plugins":{"audio":{"mp3":{"description":"Android平台录音支持MP3格式文件"}}}},"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"3.3.11","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html"}}

2
uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/pages/index/scan.js
File diff suppressed because it is too large
View File

2
uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/pages/sample/ext-component.js
File diff suppressed because it is too large
View File

2
uniapp示例工程源码/unipluginDemo/unpackage/dist/build/app-plus/pages/sample/ext-module.js
File diff suppressed because it is too large
View File

4
uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/app-config-service.js

@ -1,8 +1,8 @@
var isReady=false;var onReadyCallbacks=[];
var isServiceReady=false;var onServiceReadyCallbacks=[];
var __uniConfig = {"pages":["pages/index/index","pages/index/ball_list","pages/index/scan","pages/sample/ext-module","pages/sample/ext-component","pages/sample/richAlert"],"window":{"navigationBarTextStyle":"black","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#F8F8F8","backgroundColor":"#F8F8F8"},"nvueCompiler":"uni-app","nvueStyleCompiler":"weex","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"unipluginDemo","compilerVersion":"3.3.11","entryPagePath":"pages/index/index","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
var __uniRoutes = [{"path":"/pages/index/index","meta":{"isQuit":true},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/ball_list","meta":{},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/scan","meta":{"isNVue":true},"window":{"navigationBarTitleText":"22222"}},{"path":"/pages/sample/ext-module","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 module"}},{"path":"/pages/sample/ext-component","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 component"}},{"path":"/pages/sample/richAlert","meta":{},"window":{"navigationBarTitleText":"RichAlert"}}];
var __uniConfig = {"pages":["pages/sample/ext-module-vue","pages/index/index","pages/index/ball_list","pages/index/scan","pages/sample/ext-module","pages/sample/ext-component","pages/sample/richAlert"],"window":{"navigationBarTextStyle":"black","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#F8F8F8","backgroundColor":"#F8F8F8"},"nvueCompiler":"uni-app","nvueStyleCompiler":"weex","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"unipluginDemo","compilerVersion":"3.3.11","entryPagePath":"pages/sample/ext-module-vue","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
var __uniRoutes = [{"path":"/pages/sample/ext-module-vue","meta":{"isQuit":true},"window":{"navigationBarTitleText":"扩展 module vue"}},{"path":"/pages/index/index","meta":{},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/ball_list","meta":{},"window":{"navigationBarTitleText":"uni-app"}},{"path":"/pages/index/scan","meta":{"isNVue":true},"window":{"navigationBarTitleText":"22222"}},{"path":"/pages/sample/ext-module","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 module nvue"}},{"path":"/pages/sample/ext-component","meta":{"isNVue":true},"window":{"navigationBarTitleText":"扩展 component"}},{"path":"/pages/sample/richAlert","meta":{},"window":{"navigationBarTitleText":"RichAlert"}}];
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,global:void 0,window:void 0,document:void 0,frames:void 0,self:void 0,location:void 0,navigator:void 0,localStorage:void 0,history:void 0,Caches:void 0,screen:void 0,alert:void 0,confirm:void 0,prompt:void 0,fetch:void 0,XMLHttpRequest:void 0,WebSocket:void 0,webkit:void 0,print:void 0}}}});

2
uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/app-service.js
File diff suppressed because it is too large
View File

2
uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/app-view.js
File diff suppressed because it is too large
View File

2
uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/manifest.json

@ -1 +1 @@
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__2B9497D","name":"unipluginDemo","version":{"name":"1.0.0","code":"100"},"description":"","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"usingComponents":true,"nvueCompiler":"uni-app","compilerVersion":3,"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"3.3.11","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html"}}
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__2B9497D","name":"unipluginDemo","version":{"name":"1.0.0","code":"100"},"description":"","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"compatible":{"ignoreVersion":true},"usingComponents":true,"nvueCompiler":"uni-app","compilerVersion":3,"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"3.3.11","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html"}}

2
uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/pages/index/scan.js
File diff suppressed because it is too large
View File

2
uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/pages/sample/ext-component.js
File diff suppressed because it is too large
View File

2
uniapp示例工程源码/unipluginDemo/unpackage/resources/__UNI__2B9497D/www/pages/sample/ext-module.js
File diff suppressed because it is too large
View File

70
uniapp示例工程源码/unipluginDemo/utils/timeFormat.js

@ -0,0 +1,70 @@
// padStart 的 polyfill,因为某些机型或情况,还无法支持es7的padStart,比如电脑版的微信小程序
// 所以这里做一个兼容polyfill的兼容处理
if (!String.prototype.padStart) {
// 为了方便表示这里 fillString 用了ES6 的默认参数,不影响理解
String.prototype.padStart = function(maxLength, fillString = ' ') {
if (Object.prototype.toString.call(fillString) !== "[object String]") throw new TypeError(
'fillString must be String')
let str = this
// 返回 String(str) 这里是为了使返回的值是字符串字面量,在控制台中更符合直觉
if (str.length >= maxLength) return String(str)
let fillLength = maxLength - str.length,
times = Math.ceil(fillLength / fillString.length)
while (times >>= 1) {
fillString += fillString
if (times === 1) {
fillString += fillString
}
}
return fillString.slice(0, fillLength) + str;
}
}
// 其他更多是格式化有如下:
// yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合
function timeFormat(dateTime = null, fmt = 'yyyy-mm-dd') {
// 如果为null,则格式化当前时间
if (!dateTime) dateTime = Number(new Date());
//兼容IOS
if(typeof(dateTime)=="string"&&dateTime.indexOf("-")>0) dateTime = dateTime.replace(/\-/g,'/')
// 如果dateTime长度为10或者13,则为秒和毫秒的时间戳,如果超过13位,则为其他的时间格式
if (dateTime.toString().length == 10) dateTime *= 1000;
let date = new Date(dateTime);
let ret;
let opt = {
"y+": date.getFullYear().toString(), // 年
"m+": (date.getMonth() + 1).toString(), // 月
"d+": date.getDate().toString(), // 日
"h+": date.getHours().toString(), // 时
"M+": date.getMinutes().toString(), // 分
"s+": date.getSeconds().toString() // 秒
// 有其他格式化字符需求可以继续添加,必须转化成字符串
};
for (let k in opt) {
ret = new RegExp("(" + k + ")").exec(fmt);
if (ret) {
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
};
};
return fmt;
}
//计算视频分钟时长,如(180s视频) a=180 返回03:00
function getDurationTime(a){
var b = ""
var h = parseInt(a/3600),
m = parseInt(a%3600/60),
s = parseInt(a%3600%60);
if(h>0){
h = h<10 ? '0'+h : h
b += h+":"
}
m = m<10 ? '0'+m : m
s = s<10 ? '0'+s : s
b+=m+":"+s
// console.log(b);
return b;
}
export {timeFormat,getDurationTime}

56
zmt_module/src/main/java/io/dcloud/zmt_module/AsyncTask.java

@ -0,0 +1,56 @@
package io.dcloud.zmt_module;
import com.alibaba.fastjson.JSONObject;
import io.dcloud.feature.uniapp.AbsSDKInstance;
public class AsyncTask {
String TAG = "zmt_module_AsyncTask ";
public interface MyTcpCallback{
void callback(Object object);
}
// TCP task
public void task(final MyTcpCallback myCallback, final Integer port){
// Android 4.0 之后不能在主线程中请求HTTP请求
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("AsyncTask thread running... port:"+port);
TcpServer server = new TcpServer();
// server.initSocket((Integer.parseInt("16666")));
server.initSocket(port);
while (true){
String tcp_receive_message = server.receiveMessage(SocketConfig.UTF_8);//接收消息
System.out.println(TAG+"接收消息:"+tcp_receive_message);
String send_msg = "App received tcp message!"; //回发socket消息确认接收
send_msg = SocketHelper.getMessageByReadLine(send_msg);
server.sendMessage(send_msg,SocketConfig.UTF_8);//回发消息
JSONObject data = new JSONObject();
data.put("threadID", Thread.currentThread().getId());
data.put("threadName", Thread.currentThread().getName());
// data.put("message", server.);
// data.put("message", tcp_receive_message);
data.put("message", tcp_receive_message);
myCallback.callback(data);//回调到zmtClass给uni端
try {
Thread.sleep(1000); //定义休眠时间
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
thread.setDaemon(true);//开启守护线程
thread.start();
}
}

62
zmt_module/src/main/java/io/dcloud/zmt_module/PermissionCheck.java

@ -0,0 +1,62 @@
package io.dcloud.zmt_module;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;
import androidx.core.app.ActivityCompat;
import androidx.core.content.PermissionChecker;
public class PermissionCheck extends Activity {
private static final String TAG = "MainActivity";
private final int ACCESS_LOCATION=1;
/**
* 获取权限可以与其他项目的权限进行统一处理
*/
private void getPermission() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
int permissionCheck = 0;
permissionCheck = this.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION); //允许一个程序访问精良位置(如GPS)
permissionCheck += this.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION); //允许一个程序访问CellID或WiFi热点来获取粗略的位置
permissionCheck += this.checkSelfPermission(Manifest.permission.CAMERA); //请求访问使用照相设备
if (permissionCheck != PackageManager.PERMISSION_GRANTED) { //未获得权限
ActivityCompat.requestPermissions(
this,// 请求授权
new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.CAMERA},ACCESS_LOCATION);// 自定义常量,任意整型
}
}
}
/**
* 请求权限的结果回调每次调用 requestpermissionsstring[]int时都会调用此方法
* @param requestCode 传入的请求代码
* @param permissions 传入permissions的要求
* @param grantResults 相应权限的授予结果:PERMISSION_GRANTED PERMISSION_DENIED
*/
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case ACCESS_LOCATION:
if (hasAllPermissionGranted(grantResults)) {
Log.i(TAG, "onRequestPermissionsResult: 用户允许权限");
} else {
Log.i(TAG, "onRequestPermissionsResult: 拒绝搜索设备权限");
}
break;
}
}
private boolean hasAllPermissionGranted(int[] grantResults) {
for (int grantResult : grantResults) {
if (grantResult == PackageManager.PERMISSION_DENIED) {
return false;
}
}
return true;
}
}

3
zmt_module/src/main/java/io/dcloud/zmt_module/TcpServer.java

@ -78,6 +78,9 @@ public class TcpServer {
}
}
public interface MySocketCallback{
void callback(Object object);
}
private String getIPAddressForNetwork() throws SocketException {
String address = null;

112
zmt_module/src/main/java/io/dcloud/zmt_module/zmtClass.java

@ -3,67 +3,111 @@ package io.dcloud.zmt_module;
import com.alibaba.fastjson.JSONObject;
import com.tencent.iot.hub.device.android.core.gateway.TXGatewayConnection;
import io.dcloud.feature.uniapp.AbsSDKInstance;
import io.dcloud.feature.uniapp.UniSDKInstance;
import io.dcloud.feature.uniapp.annotation.UniJSMethod;
import io.dcloud.feature.uniapp.bridge.UniJSCallback;
import io.dcloud.feature.uniapp.common.UniModule;
import android.util.Log;
import java.util.HashMap;
import java.util.Map;
public class zmtClass extends UniModule {
String TAG = "zmt---";
final AbsSDKInstance uniSDK = this.mUniSDKInstance;//定义uniSDK
//run ui thread
@UniJSMethod(uiThread = true)
public void tcpAsyncFunc(JSONObject options, final UniJSCallback callback) {
Log.e(TAG, "tcpAsyncFunc--zmt:"+options);
//启动线程
// MyThread mt = new MyThread();
// mt.run();
if(callback != null) {
JSONObject data = new JSONObject();
data.put("code", "已开启服务,等待接收数据");
// callback.invoke(data);
data.put("msg", "已接收参数,处理中..."+options.toJSONString());
callback.invokeAndKeepAlive(data);
}
Integer port = 16666;//默认端口当uni传递port参数时采用传递port初始化tcp
String s_port = options.getString("port");
if (!s_port.isEmpty()){
Log.e(TAG, "tcpAsyncFunc--port:"+s_port);
port = Integer.parseInt(s_port);
}
// Android 4.0 之后不能在主线程中请求HTTP请求
new Thread(new Runnable(){
new AsyncTask().task(new AsyncTask.MyTcpCallback() {
@Override
public void run() {
System.out.println("MyThread thread running...");
TcpServer server = new TcpServer();
server.initSocket((Integer.parseInt("16666")));
while (true){
String message = server.receiveMessage(SocketConfig.UTF_8);
System.out.println(TAG+"接收消息:"+message);
JSONObject data = new JSONObject();
data.put("code", message);
public void callback(Object object) {
// JSONObject data = new JSONObject();
// data.put("code", object);
// callback.invoke(data);
callback.invokeAndKeepAlive(data);
String send_msg = "1111111111111";
send_msg = SocketHelper.getMessageByReadLine(send_msg);
server.sendMessage(send_msg,SocketConfig.UTF_8);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Map<String,Object> params=new HashMap<>();
params.put("key","你好啊大家");
uniSDK.fireGlobalEventCallback("myEvent", params);//发送全局参数直接回调
callback.invokeAndKeepAlive(object);//使用jsCallback回调
}
}).start();
},port);
}
// Android 4.0 之后不能在主线程中请求HTTP请求
// new Thread(new Runnable(){
// @Override
// public void run() {
// System.out.println("MyThread thread running...");
//
// TcpServer server = new TcpServer();
// server.initSocket((Integer.parseInt("16666")));
//
// while (true){
// String message = server.receiveMessage(SocketConfig.UTF_8);
// System.out.println(TAG+"接收消息:"+message);
//
// JSONObject data = new JSONObject();
// data.put("code", message);
//// callback.invoke(data);
// callback.invokeAndKeepAlive(data);
//
// String send_msg = "1111111111111";
//
// send_msg = SocketHelper.getMessageByReadLine(send_msg);
// server.sendMessage(send_msg,SocketConfig.UTF_8);
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
//
// }
//
// }
// }).start();
}
//定义MyTcpCallback
public interface MyTcpCallback{
void callback(Object object);
}
// public void task(final AsyncTask.MyCallback myCallback){
// Thread thread = new Thread(new Runnable() {
// @Override
// public void run() {
// try{
// Thread.sleep(3000);
// }catch (InterruptedException e){
// e.printStackTrace();
// }
// int sum = 0;
// for(int i=0;sum<99;sum++){
// sum+=i;
// }
// myCallback.callback(sum);
// }
// });
// thread.start();
// }
// @UniJSMethod(uiThread = true)
// public void testAsyncFunc(JSONObject options, UniJSCallback callback) {
// Log.e(TAG, "testAsyncFunc--zmt:"+options);

Loading…
Cancel
Save