我想通过套接字共享 apk 文件。我已经尝试将“Hello World”消息从一个 Android 设备发送到另一个 Android 设备,并且效果非常好。
var socket = await FlutterP2p.openHostPort(port);
setState(() {
_socket = socket;
});
FlutterP2p.acceptPort(port);
Run Code Online (Sandbox Code Playgroud)
我不知道如何共享应用程序,但是我有我选择的每个 Android 应用程序的路径。
这是我到目前为止所尝试过的
Application app = element['Application'];
Uint8List file = await File(app.apkFilePath).readAsBytes();
socket.write(file);
Run Code Online (Sandbox Code Playgroud)
在接收端
socket.inputStream.listen((data){
File app = File("$path/base.apk");
// I think this is wrong as we cant write anything to apk file
// And so I tried this (don't mind the variable name)
File app = File("$path/base.txt");
app.writeAsBytes(event.data); //event.data is Uint8List
app.rename("base.apk"); // this doesn't work either.
}); …
Run Code Online (Sandbox Code Playgroud)