How to share an apk file with P2P socket in Dart flutter. (flutter_p2p)

Viewed 485

I want to share an apk file over the socket.. I've already tried sending the "Hello World" message from one android device to another, and it works perfectly.

      var socket = await FlutterP2p.openHostPort(port);
      setState(() {
        _socket = socket;
      });
      FlutterP2p.acceptPort(port);

I have no idea of how to share an application, however I have the path to each android app that I've selected..

This is what I've tried till now

     Application app = element['Application'];
     Uint8List file = await File(app.apkFilePath).readAsBytes();
     socket.write(file);

and on the receiver side

     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.
     });

But this creates random named files at the "Data" location of the application. and renaming methods does nothing either..

I'm using the flutter_p2p package..

I have no clue of how to do this.. NO Documentation found..

0 Answers
Related