I am new for Android. I am trying to upload any type of file(like audio,video,document,image.. formats) from android SD card to php server, but am not getting clear code.I got some solution here ,but they mentioned existing particular type of file & Specific path.I want all type of fie upload from SD card.
Asked
Active
Viewed 3,426 times
1
-
The code in the link doesn't filter on the extension neither the mime type, that should work for you. – Loïc Feb 27 '14 at 07:06
-
Thanks for quick response Loic. I dont know how to upload mine type and pick file from SD card.I dont want mention existing file name.If have idea share me. – Raj Feb 27 '14 at 07:12
2 Answers
1
from this method u can access all file from sd card this is my code
public void getAllFile(File dir) {
File listFile[] = dir.listFiles();
if (listFile != null) {
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
getAllFile(listFile[i]);
} else {
listFile[i].getName();
System.out.println("your file is "+listFile[i].getName());
}
}
}
}
best of luck dude :)

Bhanu Sharma
- 5,135
- 2
- 24
- 49
0
//call this method to select file from device memory
static Uri url;
String path;
private void showFileChooser() {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
i.addCategory(Intent.CATEGORY_OPENABLE);
i = Intent.createChooser(i, "Choose a file");
startActivityForResult(i, FILE_SELECT_CODE);
}
//here you will get the path of selected file
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(resultCode==-1)
{
Log.w("Request Code", ""+requestCode);
Log.w("Result Code", ""+resultCode);
path = getRealPathFromURI( data.getData());
try {
Log.w("Intent", data.getData().toString());
} catch (Exception e) {
// TODO Auto-generated catch block
Log.w("Error", e.toString());
}
}
}
//get exact path of file -- exact path is stored in path variable
public String getRealPathFromURI (Uri contentUri)
{
String path = null;
String[] proj = { MediaStore.MediaColumns.DATA };
if("content".equalsIgnoreCase(contentUri.getScheme ()))
{
Cursor cursor = getContentResolver().query(contentUri, proj, null, null, null);
if (cursor.moveToFirst()) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
path = cursor.getString(column_index);
}
cursor.close();
return path;
}
else if("file".equalsIgnoreCase(contentUri.getScheme()))
{
return contentUri.getPath();
}
return null;
}

Yogesh Lakhotia
- 888
- 1
- 13
- 26