android - Send simple String instead of file via WiFi P2P -


I'm trying to get an example of running a WiFi peer-to-peer, where a user is the other The user can send the string. In, only files are sent - How can I send a string without the files and the stuff?

The code from the document:

Sending:

  OutputStream output stream = socket.getOutputStream (); ContentResolver cr = context.getContentResolver (); InputStream inputstream = faucet; Inputstream = cr.openInputStream (Uri.parse ("path / to / picture.jpg")); While ((len = inputstream.read (buf))! = -1) {outputstream.write (buf, 0, len); } Outputstream.close (); InputStream.close ();  

Getting:

  last file f = new file (environment .getExternalStorage directory () + "/" + context .getPackageName () + "/ Wifip2pshared-" + System.currentTimeMillis () + ".jpg"); File diary = new file (f.getParent ()); If (! Dirs.exists ()) dirs.mkdirs (); F.createNewFile (); InputStream inputstream = client.getInputStream (); CopyFile (inputstream, new file-output stream (F)); ServerSocket.close (); Return f.getAbsolutePath ();  

How do I need to modify the strings to send / receive this code? (Without file).

  1. Convert your string to a byte in your OutputStream
Write that array to String.getBytes ()

  • Comments