On Android (8.0), I'm trying to create a local html file that includes links to some local files that can't be viewed directly by Chrome, like <a href="relative_path_to_file/file.docx">. In a normal web browser (i.e. on a PC), I can click the link and it will open the file in its default viewer. On Android, if I open one of the local html files in Chrome and click one of those links, it directs me to content://nextapp.fx.FileProvider/path_to_file/file.docx, showing "Your file was not found." I do have an appropriate app installed to view the file (I can open it via a file explorer app). I would like to understand how I can structure the URLs such that docs of various types (i.e. docx, xlsx, pdf, etc) can be accessed via the links that refer to them - clicking the link should offer to open the file, as it does when accessing the file from a file manager.
I tried rewriting the links to an absolute path, i.e. "/storage/emulated/0/path/file.docx." The result is the same.
I tried rewriting the links to "file:///storage/emulated/0/path/file.docx." Chrome just redirects to about:blank.
I tried opening the html doc with "HTML Viewer" rather than Chrome. The behavior is more or less the same (in the first case it redirects to about:blank, in the second it says "No app available to open link.")
How can I structure the link so it can be clicked & open the referred-to file in appropriate viewer?
Finally figured it out. A working link to open the local file in its default viewer looks like:
"intent:///abs/path/to/file.docx#Intent;scheme=file;action=android.intent.action.VIEW;end;"
...With one important caveat: it breaks if there are any "dots" in the path (i.e. I had the files in a .hiddenFolder, which apparently causes Chrome to be unable to figure out the intent link).
Reference: https://developer.chrome.com/multidevice/android/intents
Related
I have a React progressive web app which contains a link to a PDF file. The app has been added to the home screen using the Google banner (https://developers.google.com/web/updates/images/2015/12/getting-started-pwa/pwa-general-2-#1x.jpg), so it is treated as an app, not a shortcut.
The problem is I cannot open the PDF file from the installed PWA on Android. I get an error saying: Cannot open PDF (pdf_name.pdf cannot be opened).
Opening the PDF from a regular browser (desktop or mobile) works. Opening from home screen app on iOS also works.
My PWA is hosted at app.domain.com, while the PDF is hosted at api.domain.com.
The link to the PDF file looks like this:
<a rel="noopener" href="https://api.domain.com/pdf_name.pdf"
target="_blank">View PDF</a>
External links that go to regular pages (not files) work.
Any ideas what might prevent Chrome from being opened from within the app?
I fixed this by simply removing the target attribute. It opens up in a new tab anyway. For PWA's on Android, specifying a new tab with the target attribute causes an error. It seems that when you manually specify a new tab the browser reacts as if there are 2 pages to download, the pdf and an empty web page (0 kb). Oddly, the Samsung Internet Browser also does this but just downloads both. The PWA Chrome Browser errors instead.
I am trying to download a pdf file using an ASP.Net MVC web application however have noticed that it always fails to download both 1) the file and 2) fail to open up the file within the browser.
Note: The link does not point to a URL + filename with a .pdf extension...it directs to a controller/action that should return the pdf.
All the correct content types/MIME types have been setup correctly:
pdf: application/PDF
ppt: application/vnd.openxmlformats-officedocument.presentationml.presentation
xlsx: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
...just not sure why it doesn't work.
Can anyone shed any light on this please.
What I would like to achieve is either viewing the file within the browser or downloading the file to the phone to view.
Note: Seems to work perfectly well on ios mobile safari browser, and all desktop browsers!
Note 2: the actual error message in the notification area in Android is:
< Untitled >
Download unsuccessful.
VS2010 VB.NET ASP.NET
I have a simple site where the user clicks a button and a pdf file is displayed in a new broswer window.
To do the this a button launches a new browser window with the following code in the page load event:
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1))
Response.Buffer = True
Response.ContentType = "application/pdf"
'Response.ContentType = "text/plain"
If Download_Flag Then
'force SaveAs (this is the download option)
Response.AppendHeader("Content-Disposition", "attachment; filename=" & "myfile" & ".pdf")
Else
'open in borwser
Response.AddHeader("Content-Disposition", "inline")
End If
Response.OutputStream.Write(PdfBuffer, 0, PdfBuffer.Length)
Response.OutputStream.Flush()
Response.OutputStream.Close()
Response.End()
PDFBuffer is a byte array containing the pdf document
This code displays the pdf file in the browser (ie, chrome, mozilla, safari?) using whatever pdf plugin is installed.
if download_flag is true then the pdf is not opened in the viewer but instead browser prompts with the save file dialog
As I said, this code works in desktop borwsers, but it does not work on an ipad or an android phone, and propably other devices as well.
The site is not mobile aware, but if need be it could, I suppose.
I know that apple does not allow downloads, and android may not be able to open open an additional window, so how can I open a pdf file on a button click on these devices? I know he ipad and the android can both open pdf files, I've done it on other sites.
My solution was to open the pdf file in the same window as the site. On android this causes a file download to which the user can go to the downloads folder and view the pdf. On ipad this opens the default pdf viewer. If ipad user download the adobe pdf viewer they can switch over to the adobe reader from the default ipad reader; the adobe reader allows print and email of document. On desktop browser this solution shows the pdf in the same window and user can use the browser's back button to get back to the site when they are done with the pdf. A more robust solution would be to detect the client and act appropriately, but with this common implementation is workable.
Speaking for Android, Content-Disposition is tricky to get working properly:
Avoiding content type issues when downloading a file via browser on Android
http://www.digiblog.de/2011/04/android-and-the-download-file-headers/
http://winzter143.blogspot.com/2012/03/android-handling-of-content-disposition.html
Is there a free way to view postscript files on android? I cannot find a solution online but surely lots of people must want to do this.
Recently Sam Buss and I realized that you can upload the PS file to Google Drive and once its uploaded to your drive, the drive viewer will open and render the PS file on your android device.
Here is a way that just worked for me on a Samsung Galaxy 5. Something similar can probably work for others. The general idea is to download the postscript file, and use an online web service to convert it to PDF, which you can then view.
Download the postscript file.
Open your browser (I use Chrome). Navigate to www.ps2pdf.com. Navigate your way to their "Convert" page, click the "Choose file" botton. Select "Documents" when it asks for "Choose an action". Go into your "Downloads" folder on your phone. Select the downloaded postscript file. Then, back on the ps2.pdf.com page, click the Convert button.
Click the active link for the converted PDF file. This opened in Adobe Reader, which is my default PDF viewer). If I want to access the file from other programs, it is in Adobe Reader's "Recent" folder in my phone's documents.
I am developing an web+cross platform app using Jquery Mobile+PhoneGap+Android. In web app, I am able to open pdf file links within my app page using iframe. But, in Phonegap generated Android build, iframe is unable to render pdf content,it is showing that iframe area as empty.How can I display the pdf file/content, whose src I know at runtime, within android webview. Thanks In Advance.
I've just published my plugin, which can open almost any type of file, which is stored locally on Android device.
Please take a look at: https://github.com/markeeftb/FileOpener
Plugin opens external application which handles the preview of the document.