I have a simple question but can't seem to find the answer anywhere I look online.
I have an activity A that downloads files from the internet and puts them to a local folder obtained by getApplicationContext().getFilesDir().getPath() which points to: "/data/data/com.myapp.android/files"
Now when the user selects a file I want to show its content and for that I do the following:
File file = new File(filePath);
Uri uri = Uri.fromFile(file);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String type = mime.getMimeTypeFromExtension(fileExtension);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(uri, type);
Intent intentChooser = Intent.createChooser(intent, "Open File");
startActivity(intentChooser);
When this executes the user is presented with the Open File dialog and after they select "Gallery" the Gallery activity appears with nothing on it.
Looking at logcat I see the following:
E/PanoMetadata(17732): Could not read file: /data/data/com.myapp.android/files/downloads/Splash.png
E/PanoMetadata(17732): java.io.FileNotFoundException: /data/data/com.myapp.android/files/downloads/Splash.png: open failed: EACCES (Permission denied)
E/PanoMetadata(17732): at libcore.io.IoBridge.open(IoBridge.java:409)
E/PanoMetadata(17732): at java.io.FileInputStream.<init>(FileInputStream.java:78)
Note the "open failed: EACCES (Permission denied)"
But the file is really there and I can display it using my activity A without a problem.
The problem seems to be that the other activity which starts using ACTION_VIEW (in this case Gallery) seems to run under different process/user so it does not have read access to my file.
My 3 questions are:
Is it possible to get the ACTION_VIEW activity to run within my process and user context (of activity A)?
How do I share files between activities? (I do not like to copy the file under /sdcard/... but if that is the only option than it will have to be.)
Is there a way to pass the file content (not file pointer) from my activity to the Gallery activity or other activities?
Regards!