title: How to Transfer files between two Android phones using Wifi Direct to Download directory of Android phone and not to Package directory
body: <p>The below line in my code transfers *.apk file to my package directory. </p>
  
  <pre><code> final File f = new File(Environment.getExternalStorageDirectory() + "/"
                          + context.getPackageName() + "/wifip2pshared-" + System.currentTimeMillis()
                          + ".apk");
  </code></pre>
  
  <p>How to modify the same so that each time it gets downloaded/transferred to downloads directory of android phone. I believe Downloads directory is a default directory in each android phone.</p>
  
  <p>Currently it gets transferred to package directory say for example "com.example.android.wifidirect"</p>
  
  <p>EDIT I made based on Manish's Solution:</p>
  
  <pre><code>@Override
          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");
                  String extStorageDirectory = Environment
                          .getExternalStorageDirectory().toString();
                  File folder = new File(extStorageDirectory, "Download");
  
  
  File file = new File(folder,"wifip2pshared-" + System.currentTimeMillis()+ ".apk");
                  try {
                      file.createNewFile();
                  } catch (IOException e1) {
                      e1.printStackTrace();
                  }
  
  
                  Log.d(WiFiDirectActivity.TAG, "server: copying files " + file.toString());
                  InputStream inputstream = client.getInputStream();
                  copyFile(inputstream, new FileOutputStream(file));
                  serverSocket.close();
                  return file.getAbsolutePath();
              } catch (IOException e) {
                  Log.e(WiFiDirectActivity.TAG, e.getMessage());
                  return null;
              }
          }
  </code></pre>