I'm trying to select pdf file from the device and upload them to the server. ACTION_GET_CONTENT
is used to select pdf from the device.
sel_book.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select PDF"), 1);
}
});
On activity result I get the Uri and save it as a String.
public void onActivityResult(int requestCode, int resultCode, Intent result) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
Uri uri = result.getData();
String uriString = uri.toString();
File myFile = new File(uriString);
path = myFile.getAbsolutePath();
}
}
}
It results the path as, /document/primary:Download/Aptitude_2016_17.pdf
. I need to use this to create a new file. File selectedFile = new File(selectedFilePath);
. But it doesn't create File. selectedFile.isFile()
returns false. I have no idea why is it. Please help me to solve this. Thanks in advance.