Browse Source

增加uni端接口:获取本机IP

module-tcpserver-mqtt-t4j-faceSDK
zmt 3 years ago
parent
commit
93198f2822
  1. 2
      app/src/main/assets/apps/__UNI__2B9497D/www/app-service.js
  2. 2
      app/src/main/assets/apps/__UNI__2B9497D/www/app-view.js
  3. 12
      uniappWWW/unipluginDemo/pages/sample/ext-module-vue.vue
  4. 22
      zmt_module/src/main/java/io/dcloud/zmt_module/zmtClass.java

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

12
uniappWWW/unipluginDemo/pages/sample/ext-module-vue.vue

@ -4,6 +4,7 @@
<button class="btn" type="primary" @click="gotoNativePage">跳转原生Activity</button>
<button class="btn" type="primary" @click="initTcp">[开启TcpServer]</button>
<button class="btn" type="primary" @click="closeTcp">[关闭TcpServer]</button>
<button class="btn" type="primary" @click="getIP">[获取IP]</button>
<text class="tips">
点击后将开启TcpServer. 本机IP: 192.168.1.64 端口16666
</text>
@ -97,6 +98,17 @@
this.log("invoke:"+JSON.stringify(ret))
})
},
getIP(){
zmtModule.getIP({
},
(ret) => {
modal.toast({
message: ret,
duration: 2
});
this.log("invoke:"+JSON.stringify(ret))
})
},
closeTcp(){
//
this.log("Click Tcp Server.")

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

@ -9,6 +9,10 @@ import io.dcloud.zmt_module.tcpServer.TCPTask;
import android.util.Log;
import java.net.SocketException;
import static io.dcloud.zmt_module.tcpServer.SocketHelper.getIPAddressForNetwork;
public class zmtClass extends UniModule {
String TAG = "module plugin";
@ -44,10 +48,26 @@ public class zmtClass extends UniModule {
// uniSDK.fireGlobalEventCallback("myEvent", params);//发送全局参数直接回调
}
//run JS thread
@UniJSMethod(uiThread = true)
public void getIP(JSONObject options, final UniJSCallback callback){
Log.e(TAG, "UniJSMethod getIP");
JSONObject data = new JSONObject();
data.put("code", "0");
try {
data.put("ip", getIPAddressForNetwork());
} catch (SocketException e) {
e.printStackTrace();
}
callback.invokeAndKeepAlive(data);
}
//run JS thread
@UniJSMethod(uiThread = true)
public void closeTcp(JSONObject options, final UniJSCallback callback){
public void closeTcp(JSONObject options, final UniJSCallback callback){ //TODO 需优化暂勿用
Log.e(TAG, "testSyncFunc--zmt2");
JSONObject data = new JSONObject();
data.put("code", "0");

Loading…
Cancel
Save