My Problem: When openFile()
intent attempts StartActivityForResult
, the application hangs with a blank screen and circular cursor. The file(s) are stored to app.
What I have done: Before and after this issue I researched how to open files by use of Intents. I found a number of similar but different approaches and either used the literal example or a combination of various examples to see if I could find and resolve the issue (see some below). I'm not receiving any type of error message that I have found, and I had the FileUriExposedException
previously but resolved it. These files are stored to the app and it may be a permissions issue and have tried what I know, including updating the manifest with for External Read and Write and added a flag setting on the intent for access.
What I'm trying to do: I'm trying to learn how to open files through intents with simple JPG images, then eventually expand to opening various file types after I understand how to do so.
Below is the current code I'm using and it included a MimeTypeMap that I tried in place of "image/jpeg" in case my syntax was not correct on the MIME Type, which did not seem to have an impact.
private void openFile(Uri uri, String fName) {
MimeTypeMap myMime = MimeTypeMap.getSingleton();
String mimeType = myMime.getMimeTypeFromExtension(getUpperBound(fName));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("content://" + uri), "image/jpeg");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent, 2);
}
An image of the resulting issue hanging and never opening below:
Some of the referenced links I tried:
https://developer.android.com/guide/components/intents-common
ACTION_VIEW intent for a file with unknown MimeType
Open File With Intent (Android)
http://www.androidsnippets.com/open-any-type-of-file-with-default-intent.html