I'm trying to parse a local .xml file using XmlPullParseFactory. I'm having trouble accessing the path "/storage/emulated/0/Download/testcards.xml" despite having applied permission in the manifest file.
public void parseXML(){
XmlPullParserFactory parserFactory;
try{
parserFactory = XmlPullParserFactory.newInstance();
XmlPullParser parser = parserFactory.newPullParser();
InputStream is = new FileInputStream(new File("/storage/emulated/0/Download/testcards.xml"));
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(is,null);
processParsing(parser);
} catch(XmlPullParserException e){
} catch (IOException e) {
}
}
My manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="demoapp1domain.demoapp1">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
.....
When I try to run my program I get:
java.io.FileNotFoundException: /storage/emulated/0/Download/testcards.xml (Permission denied)
This is the code for getting the path:
public void startFileExplorer(View view) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/xml");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(Intent.createChooser(intent, "Select your flashcards .XML-file "), REQUEST_CHOOSER);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CHOOSER:
if (resultCode == RESULT_OK) {
final Uri uri = data.getData();
String myXMLFilePath = uri.getPath();
}
break;
}
}
Any idea why permission is denied?
android {
compileSdkVersion 26
defaultConfig {
applicationId "demoapp1domain.demoapp1"
minSdkVersion 21
targetSdkVersion 26