I've found my own solution, alot easier than the above in my opinion. But thanks anyway @Pedram
In onCreate :
Uri data = getIntent().getData();
if(data!=null)
{
getIntent().setData(null);
try {
importData(data);
} catch (Exception e) {
// warn user about bad data here
Log.d("Docspro", "Opening file failed");
e.printStackTrace();
}
}
Then made a method in the same class :
private void importData(Uri data) {
final String scheme = data.getScheme();
if(ContentResolver.SCHEME_CONTENT.equals(scheme)) {
try {
ContentResolver cr = this.getContentResolver();
InputStream is = cr.openInputStream(data);
if(is == null) return;
StringBuffer buf = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String str;
if (is!=null) {
while ((str = reader.readLine()) != null) {
buf.append(str + "\n" );
}
}
is.close();
// perform your data import here…
ParseXML(buf.toString());
}
catch(IOException e){
}
}
}
Then the final method the parser :
public void ParseXML(String file)
{
try {
InputStream is = new ByteArrayInputStream(file.getBytes("UTF-8"));
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(is);
//optional, but recommended
//read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
doc.getDocumentElement().normalize();
Log.i("Testing", "Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("Settings");
Log.i("Testing","----------------------------");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
Log.d("Testing", "\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
DCSEmail = eElement.getElementsByTagName("User").item(0).getTextContent();
if(DCSEmail.equals(Settings.getEmail()))
{
Settings.setAccount(true);
Log.d("waarde account", "Waarde : " + Settings.getAccount() + " & Waarde DCSEMAIL : " + DCSEmail);
}
else
{
Settings.setAccount(false);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Sources : http://richardleggett.co.uk/blog/2013/01/26/registering_for_file_types_in_android/
http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/
I've adapted the methods to my own xml file i needed to readout. Hope this will help anyone else in the future!
Note: the importData gave the file as the content example : (picture them with bracket <>)
xml
config
settings
etc...
So to fix this i just used a inputstream with bytearrayinputstream.