|
|
@ -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); |
|
|
|