Browse Source

add interface

module-tcpserver-mqtt-t4j-faceSDK
zmt 3 years ago
parent
commit
fa7bb03e1b
  1. 4
      zmt_module/src/main/java/io/dcloud/zmt_module/AsyncTask.java
  2. 12
      zmt_module/src/main/java/io/dcloud/zmt_module/MyCallbackInterface.java
  3. 30
      zmt_module/src/main/java/io/dcloud/zmt_module/zmtClass.java

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

@ -9,7 +9,7 @@ public class AsyncTask {
String TAG = "zmt_module_AsyncTask ";
public interface MyTcpCallback{
void callback(Object object);
void tcpCallback(Object object);
}
// TCP task
@ -37,7 +37,7 @@ public class AsyncTask {
// data.put("message", server.);
// data.put("message", tcp_receive_message);
data.put("message", tcp_receive_message);
myCallback.callback(data);//回调到zmtClass给uni端
myCallback.tcpCallback(data);//回调到zmtClass给uni端
try {
Thread.sleep(1000); //定义休眠时间

12
zmt_module/src/main/java/io/dcloud/zmt_module/MyCallbackInterface.java

@ -0,0 +1,12 @@
package io.dcloud.zmt_module;
public class MyCallbackInterface {
public interface MyTcpCallback{
void callback(Object object);
}
public interface UniCallback{
void callback(Object object);
}
}

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

@ -1,6 +1,7 @@
package io.dcloud.zmt_module;
import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.bridge.JSCallback;
import com.tencent.iot.hub.device.android.core.gateway.TXGatewayConnection;
import io.dcloud.feature.uniapp.AbsSDKInstance;
@ -14,21 +15,23 @@ import android.util.Log;
import java.util.HashMap;
import java.util.Map;
public class zmtClass extends UniModule {
public class zmtClass extends UniModule implements AsyncTask.MyTcpCallback{
String TAG = "zmt---";
final AbsSDKInstance uniSDK = this.mUniSDKInstance;//定义uniSDK
public UniJSCallback uniTcpStartCallback;
//run ui thread
@UniJSMethod(uiThread = true)
public void tcpAsyncFunc(JSONObject options, final UniJSCallback callback) {
Log.e(TAG, "tcpAsyncFunc--zmt:"+options);
uniTcpStartCallback = callback;
if(callback != null) {
JSONObject data = new JSONObject();
data.put("msg", "已接收参数,处理中..."+options.toJSONString());
callback.invokeAndKeepAlive(data);
}
Integer port = 16666;//默认端口当uni传递port参数时采用传递port初始化tcp
@ -40,13 +43,10 @@ public class zmtClass extends UniModule {
new AsyncTask().task(new AsyncTask.MyTcpCallback() {
@Override
public void callback(Object object) {
// JSONObject data = new JSONObject();
// data.put("code", object);
// callback.invoke(data);
Map<String,Object> params=new HashMap<>();
params.put("key","你好啊大家");
uniSDK.fireGlobalEventCallback("myEvent", params);//发送全局参数直接回调
public void tcpCallback(Object object) {
// Map<String,Object> params=new HashMap<>();
// params.put("fireGlobalEventCallback","全局事件测试");
// uniSDK.fireGlobalEventCallback("myEvent", params);//发送全局参数直接回调
callback.invokeAndKeepAlive(object);//使用jsCallback回调
}
@ -86,6 +86,18 @@ public class zmtClass extends UniModule {
// }).start();
}
public void callbackOnce(JSONObject data, JSCallback callback){
// JSONObject data = new JSONObject();
// data.put("code", object);
callback.invoke(data);
}
@Override
public void tcpCallback(Object object) {
System.out.println("6666666"+object.toString());
uniTcpStartCallback.invokeAndKeepAlive(object);
}
//定义MyTcpCallback
public interface MyTcpCallback{
void callback(Object object);

Loading…
Cancel
Save