how to open sdcard memory and select pdf file to get its path for uploading it in android
I want to upload a file which is stored in sdcard to php server.To upload a file i need the filepath.When i am giving the path in application my file is getting uploaded to php server.For this i have used code from following url Android file uploader with server-side php and it working nice.But here the path is given in source code only.But i donot want to g开发者_StackOverflow社区ive the path in my application.I want to open the sdcard and then select the file which i want to upload at run time.so my question is how to get the filepath of pdf at run time on selecting pdf file from sdcard so that i can use the path to upload that file. thank you
this is what i use to get video files. you can change them for pdf.
private static final int SELECT_VIDEO_DIALOG = 1;
...
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"), SELECT_VIDEO_DIALOG);
and in your onActivityResult
public void onActivityResult(int requestCode, int resultCode, Intent result) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_VIDEO) {
Uri data = result.getData();
if(data.getLastPathSegment().endsWith("mp4")){
Player.show(this, data);
} else {
Toast.makeText(this, "Invalid file type", Toast.LENGTH_SHORT).show();
}
}
}
}
this will open file manager applicatons like FileEexpert, astro, Gallery ... and you can browse and select the file.
精彩评论