XxGoliathusxX XxGoliathusxX - 4 months ago 22
Java Question

Android select and open file with custom extension

Which mimetype is necessary to give the user the opportunity to select a custom file (here: .oli) via the filebrowser? I already created one for xml. What do I have to change?

Intent chooseFileXML = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(new Helper(FunctionsActivity.this).getPathToAppFolder());
chooseFileXML.setDataAndType(uri, "text/xml");
Intent intentXML = Intent.createChooser(chooseFileXML, getString(R.string.importXMLDatei));
startActivityForResult(intentXML, REQUEST_CODE_IMPORT_XML_FILE);

Answer

Change text/xml to */*.

BTW, note that ACTION_GET_CONTENT does not take a Uri, so do not expect apps to pay any attention to that Uri.

Comments