connect3('123123', '192.168.0.122', 80);
function connect3(str, ip, port) {
if (plus.os.name == "Android") {
var Socket = plus.android.importClass("java.net.Socket");
var PrintWriter = plus.android.importClass("java.io.PrintWriter");
var BufferedWriter = plus.android.importClass("java.io.BufferedWriter");
var OutputStreamWriter = plus.android.importClass("java.io.OutputStreamWriter");
var BufferedReader = plus.android.importClass("java.io.BufferedReader");
var InputStreamReader = plus.android.importClass("java.io.InputStreamReader");
//测试改良
var StrictMode = plus.android.importClass("android.os.StrictMode");
var Build = plus.android.importClass("android.os.Build");
if (Build.VERSION.SDK_INT > 9) {
var policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
var socket = new Socket(ip, port);
var outputStreamWriter = new OutputStreamWriter(socket.getOutputStream());
var bufferWriter = new BufferedWriter(outputStreamWriter);
var out = new PrintWriter(bufferWriter, true);
out.println(str);
var inputStreamReader = new InputStreamReader(socket.getInputStream());
var br = new BufferedReader(inputStreamReader);
var msg = br.readLine();
//while(true)
{
if (msg != null) {
console.log(msg);
}
//msg = br.readLine();
}
}
//console.log(mac);
alert("Done");
}
ssyi
你好,请问uniapp安卓连接Wi-Fi打印机还在做吗,我现在卡在指令上面了,希望能借鉴下您的经验。非常感谢
2023-01-11 10:09