How to open a local application file in another application with the intention?

To preface to my question, a couple of things need to be noted. In this case, I do not want to store the specified file on the SD card. The file also cannot be stored directly in the local application file directory. It must be in a subdirectory, so it cannot write the file using openFileOutput () and MODE_WORLD_READABLE.

An application can download small file files, such as PDF files, and save them locally in a subdirectory. I would like the user to open these files if they have an application that can open them.

For example, there is an intention to send a PDF:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(path), "application/pdf");
startActivity(intent);

the path looks something like this: /data/data/packagename/files/subdir/example.pdf

This intention will open the PDF viewer, but the viewer will not be able to open the file. I assume this is a permissions issue. I tried Mark Murphy's suggestion: http://groups.google.com/group/android-developers/browse_thread/thread/4e55d869213483a9/b7270078ac1a2744?lnk=raot use Runtime.getRuntime().exec("chmod 755 " + fileName);, but that didn't make any difference. He also suggested a content provider, but I would like to avoid this if I can, because it seems that I just need to transfer this file to another application.

If the content provider is the only option, do I need to save the file in the content provider or can I just use the content provider as a passage to get it in another application when I need to?

Thank you, let me know if I am not clear.

+3
2

, ( ), , . , " ", , .

+1

android:sharedUserId:

Linux, . Android . , , - , . , , .

, , (AFAIK). sharedUserId , .

, , PDF ? , Android .

0

Source: https://habr.com/ru/post/1773553/


All Articles