How to add text as prefix - android

I wanted to open a file without downloading it so i used window.open in InAppBrowser and it works fine in ios... But i am not able to open a pdf file this way on android.
I was able to open a pdf file using google doc by prefixing like my url:
https://docs.google.com/gview?embedded=true&url=<my_url>
Now its opening pdf files, but files with images (.png) or text (.txt) cannot be opened this way, because they will be shown as html files.
So, when i get a pdf file on an android device it should check if the last three characters are matching (pdf) and in that case add a prefix to open the pdf file. All other files should work fine.

How about:
String url = "my_pdf.pdf";
if(url.endsWith(".pdf")){
url = "https://docs.google.com/gview?embedded=true&url=" + url;
}

Related

File Upload using file input with Ionic (Selection of file using Native File Browser )

In my ionic app markup i have
<input type="file" id="file" />
in my controller i am getting the file on selection from file manager
fileinput.addEventListener('change', function (event) {
var file = event.target.files[0];
console.log(file);
This works well when i upload images or videos .and also if use the file manager option from the image below . but i encounter problems when uploading audio from quick links list or if use third party browser to get the file. in most other case the File object is returned and i can upload it successfully .
but i am encountering two problems
1) when i use the quick links on the sidebar to upload an audio file which lists all audio files with their names .On clicking a file from this list i do not get the extension nor the content-type in the file object which i need . But the same works if i use the file manager options and navigate to the file . it's almost as if the audio quick link list just has few details and does not have extension or content-type details .
2) If i use the third -party explorer like ES explorer or the music app shown in sidebar of the image the App crashes and stops .
So is there any other way to navigate to a file to upload from the app or am i doing something wrong . ImagePicker cordova plugin's . limitation of just choosing images is the problem or else would have used that
Android does not give the original file name and file type using the above approachand it is a security issue from android. So, i had to make below solution for retrieving the correct file name, file type, file size and the file data in base64.
You can follow my solution here.

How to open a PDF file onclick of a button in Android?

I need to save PDF file when my app installs and then open it when a user clicks on a button. I found many solutions but was not able to integrate them into one.
Try this code, display pdf file from a file location (works from any file location, not SDcard specific)
How to open a PDF via Intent from SD card
I was doing this in work today and it is not that easy.
1) saving the file is not difficult any normal file code will work for a pdf file.
2) showing the pdf you have two options you can display a pdf in a webview if the device has internet access by displaying a Webview and loading google docs with you pdf file at the end of the url
3) or you can create an intent and see if the device has an application that will display the file, you will need to use a FileProvider to get it to run but there is a good post
https://developer.android.com/reference/android/support/v4/content/FileProvider.html

ANDROID - How to open a pdf url which does not have a .pdf extension?

I am trying to open a url which is actually a pdf file but it does not have .pdf extension in android webview BUT it does not works. It directly downloads. But when i open the url in WEB browser, the pdf file opens perfectly.
Since this url does not have .pdf extension, I can not use google docs as well. Also tried to download and open the file using any pdf viewer app, it also fails. The main reason is my Url does not have .pdf extension. Is there any other solution?
I think you are not setting the content type as pdf(MIME). Thats why you are getting problem when you are downloading the pdf content.
See this post for more details.
Proper MIME media type for PDF files
MIME TYPES
Render a PDF file using Java on Android
you can see this .pdf extension is not necessary

Using Pdf.js in Android hybrid app to load local files

I am developing an app for android using Sencha touch and Cordova which needs to load PDF files.I found the Child browser support on PDF is not there for Android.So I decided to use PDF.js.I am using the following line of code to open the PDF file :
window.open(\''+ ROOT_FOLDER+'/app/util/PDFJS/web/viewer.html?file='+ROOT_FOLDER + '<Path to PDF file>\'
ROOT_FOLDER is the local file path URL like file://app/utils.."
But the pdf is not loading in this case and it is throwing an exception like
XMLHttpRequest cannot load file:///android_asset/www/<path to PDF file>. Cross origin requests are only supported for HTTP.
Please let me know how to fix this issue, or how to load PDF files from local location using PDF.js
If you want to load the files from local location, then it should be present in the same folder with viewer.html. In short the PDF should not be outside the main folder where all these html and js files are present.

Conversion of HTML page into pdf file in Android

We have to generate pdf file using html file.
For e.g. we have file "mypage.html" we have to show all page data as it is in pdf file.
Every time in application we will receive new html pages & we have to show as it is in pdf file.
Can we know how to do this by using iText or any third party libraries ?

Categories

Resources