The below line in my code transfers *.apk file to my package directory.
final File f = new File(Environment.getExternalStorageDirectory() + "/"
+ context.getPackageName() + "/wifip2pshared-" + System.currentTimeMillis()
+ ".apk");
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.
Currently it gets transferred to package directory say for example "com.example.android.wifidirect"
EDIT I made based on Manish's Solution:
@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;
}
}