I'm trying to parse a simple xls File from my device, here is the code i wrote until now, but I can't figure it out why my file is not found by my app .
here the code i wrote until now
In the resultActivity:
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, data.getData().getPath());
ParseFileAggiornamentoAsyncTask asyncTaskLetturaFile = new ParseFileAggiornamentoAsyncTask(MainActivity.this,file);
asyncTaskLetturaFile.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
except other things, in the asynctask there is a control like file.exist()
which return always false, so i'm not able to read it and other things.
What i'm doing wrong?
UPDATE FROM COMMENTS
here is the code that trigger my startActivityForResult
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MainConstant.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
}else {
Intent fileintent = new Intent(Intent.ACTION_GET_CONTENT);
fileintent.setType("*/*");
fileintent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(Intent.createChooser(fileintent, "Select a File to Upload"), PICKFILE_RESULT_CODE);
} catch (ActivityNotFoundException e) {
Toast.makeText(MainActivity.this, MainActivity.this.getString(R.string.generic_error), Toast.LENGTH_LONG).show();
Log.e("tag", "No activity can handle picking a file. Showing alternatives.");
}
return true;
}