I am maintaining a legacy Java / C++ application for Android which is backwards compatible to some API 18. It contains a rudimentary e-mail client.
Users receive e-mails with various attachments (HTML, PDF, JPG, MP3, MP4, XLS) and want to be able to open them in external applications. Prior to Android Q, I just saved the attachments to disk and invoked an intent with ACTION_VIEW on the file:///uri to the saved attachment.
This stopped working in Android Q with the new restrictions on storage access. Even if I save a HTML file to, say, Download/ directory, Chrome won't open it from an ACTION_VIEW intent: the error is ERR_ACCESS_DENIED.
I don't know how to fix this problem with the new scoped storage. Is there even a unified way how to open file types as different as PDF, HTML, JPG, MP3, MP4, XLS in external applications using intents? Or do I have to branch my code according to the type of the media and use some different approaches and directories for images, sounds, video and documents?
Is ACTION_VIEW still universally capable of opening files such as HTML, or has it been restricted to media files only? I would be happy to have an universal way of opening all temporarily saved attachments (smaller code to maintain is always better), but I am not sure if it is possible at all anymore.
Any help is appreciated.
Related
I have a chat app where users share images/video/audio etc. I need organized my directory structure, where i need to keep sent files in separate sub-folder and hide it from gallery apps but user can able to locate with file manager apps.
The only things comes in my mind that create .nomedia file in sent folders but in android 11+ we can't create files just like that. Our users gallery apps messed up with sent and receive images, I am not able to find any solution on StackOverFlow and on other documentations or google search.
On Android 11+ i am using MediaStore to read and write media files. Anyone have any idea how can i create .nomedia files in External Storage like Pictures/Movies/Documents etc.
I am creating .nomedia below andoird 10 like this but i have no idea how to create in android 11+
File file = new File(dir+".nomedia");
file.createNewFile();
There is a android app named taaghche which you can purchase and read pdf books etc...
I purchased a book and I want to be able to read it on PC not android, and also be able to highlight the text (which is not allowed in the app), But The app stores the pdfs so that the pdf files only opens in the app itself and if you try to open the pdf in another device you'll get the error:
Note that the app actually stores the pdf along with a file with no extension and the same name.
I think the app uses the file with no extension to give permission to the pdf file to be opened.
Here is the two files in a zip to download and have a look.
http://langfox.ir/download/pdfs.zip
Any idea or solution or clue to open this file is greatly appreciated.
The pdf looks encoded/encrypted (I maybe wrong) but I would expect to see a Pdf header, and I don't.
The file without an extension is a JFIF file (JPEG File Interchange Format), if you change the extension to Jpg, or JFIF, you should be able to view it as an image. Or in C# you can just use the Bitmap or Image class to load it
Image.FromFile(theFileName);
I use Apache PDFBox library to create pdf-files. It creates files with the XFA structure. Applications on PC, Mac or Linux can read these files without any problems. But Android devices cannot do it. I see the following error message in the pdf-file:
"Please wait... If this message is not eventually replaced by the proper contents of the document, your PDF viewer may not be able to display this type of document".
I am trying to find a solution to create pdf files that could be read by Android devices. I cannot find any information how to do it.
Did anyone do something like that?
If you generate a non-XFA PDF you'll probably have more luck with it. The XFA spec is large, complicated and not well supported. Adobe Reader supports it but not many other readers (on Android or on desktop).
Both these are used by different apps. Facebook shared with File Uris and Whatsapp with Content Uris. If my app can share Videos and pictures, which one should I use?
Also, if my app should accept videos and pictures, for which type should I be prepared? And if for both, should I convert the Content URI into a File Uri or the other way around?
If my app can share Videos and pictures, which one should I use?
On Android 7.0+, you have little choice but to share using a content Uri, such as from FileProvider.
On Android 6.0 and older, if the content is on internal storage, you also have to use FileProvider, as third-party apps have no access to your portion of internal storage. If the content is on external storage, you could use either file or content. The older the device, the more likely it is that pre-installed apps will only support file.
if my app should accept videos and pictures, for which type should I be prepared?
Ideally, both. If by "accept" you mean via ACTION_SEND, you have no choice but to support both. For ACTION_VIEW and Intent actions like it, where the data facet of an Intent is used for the Uri, use the <data> element to advertise which scheme(s) you support.
should I convert the Content URI into a File Uri or the other way around?
Neither. You consume the content from its original source. A ContentProvider supports both schemes, for things like getType() and openInputStream().
I need to either play or download audio/video files hosted on a server.
While downloading, I need the file to be downloaded in compressed size.
How to achieve that?
Any help would be appreciated.
Audio and video file formats typically employ compression already, so you can't generally do any further compression on them. Thus the good news is that you have nothing to do - your current downloading mechanism already includes compression!