Q:

client.getInputStream returns null

I am trying to use the WifiDirect demo api to send a recorded audio to another android device but input stream from the socket always returns null.
Any help is much appreciated.
Here are portion of the code
protected String doInBackground(Void... params) {
        try {
            ServerSocket serverSocket = new ServerSocket(8988);
            Log.d(WiFiDirectActivity.TAG, "Server: Socket opened");
            Socket client = serverSocket.accept();
            Log.d(WiFiDirectActivity.TAG, "Server: connection done");
            final File f = new File(Environment.getExternalStorageDirectory(), File.separator + "SuDAB/received/"
                    + "sudab-" + System.currentTimeMillis()
                    + ".3gp");

            File dirs = new File(f.getParent());
            if (!dirs.exists()) {
                dirs.mkdirs();
            }
            f.createNewFile();

            Log.d(WiFiDirectActivity.TAG, "server: copying files " + f.toString());
            InputStream inputstream = client.getInputStream(); 

            copyFile(inputstream, new FileOutputStream(f));
            serverSocket.close();
            return f.getAbsolutePath();
        } catch (IOException e) {
            Log.e(WiFiDirectActivity.TAG, e.getMessage());
            return null;
        }
    }

and
 public static boolean copyFile(InputStream inputStream, OutputStream out) {
    byte buf[] = new byte[1024];
    int len;
    long startTime = System.currentTimeMillis();
    if (inputStream == null) {
        return false;
    }
    try {
        while ((len = inputStream.read(buf)) != -1) {
            out.write(buf, 0, len);
        }
        out.close();
        inputStream.close();
        long endTime = System.currentTimeMillis() - startTime;
        Log.v(WiFiDirectActivity.TAG, "Time taken to transfer all bytes is : " + endTime);

    } catch (IOException e) {
        Log.d(WiFiDirectActivity.TAG, e.toString());
        return false;
    }
    return true;
}

this is how i pass the file to be sent to the FileTransferService
mContentView.findViewById(R.id.btn_start_client).setOnClickListener(
            new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // Allow user to pick an image from Gallery or other
                    // registered apps
                    TextView statusText = (TextView) mContentView.findViewById(R.id.status_text);
                    statusText.setText("Sending: " + lastFile);
                    Log.d(WiFiDirectActivity.TAG, "Intent----------- " + lastFile);
                    Intent serviceIntent = new Intent(getActivity(), FileTransferService.class);
                    Log.d(WiFiDirectActivity.TAG, "File transfer service created...");
                    serviceIntent.setAction(FileTransferService.ACTION_SEND_FILE);
                    serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_PATH, lastFile);
                    serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_ADDRESS,
                            info.groupOwnerAddress.getHostAddress());
                    serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_PORT, 8988);
                    getActivity().startService(serviceIntent);
                }
            });

A:

serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_PATH, lastFile);

should be 
serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_PATH, "file://"+lastFile);

instead.

