Jay6395558
Posts: 0
Joined: Thu Nov 07, 2013 8:17 pm

Open pdfs from database in Adnroid

So, I added the code and the pdf attempts to open up in Google docs but I get this result rather than the pdf opening.

Image

Jay6395558
Posts: 0
Joined: Thu Nov 07, 2013 8:17 pm

Open pdfs from database in Adnroid

Also, after four attempts at opening pdfs this way I get a message that says, "You've reached the bandwidth limit for viewing or downloading files that aren't in Google Docs format." With that in mind, it is clear to me that I don't want to go this route for opening pdfs with an Android phone. What code can I provide that will only allow the user to download the pdf onto their phone where they have to use their own phone's pdf viewer?

Also, I am currently using this code for the iphone.

codewindow.open('https://api.appery.io/rest/1/db/files/527be05fe4b0157abfe953f4/6834ad8c-3f4a-40bc-a2d9-5078814e9e13.MI-3120_Family_of_Synthesized_Signal_Sources.pdf', '_blank','EnableViewPortScale=yes'); /code

It works great so if I add any kind of code that makes Android users download a pdf will that mess up iphone users?

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Open pdfs from database in Adnroid

Hello Jay,

You can use function Apperyio.getTargetPlatform() if you want check operation system(for android it returns 'A').
This topic help you to open local pdf file: https://getsatisfaction.com/apperyio/...
For downloading file you can use PhoneGap API FileTransfer: http://docs.phonegap.com/en/3.3.0/cor...

Jay6395558
Posts: 0
Joined: Thu Nov 07, 2013 8:17 pm

Open pdfs from database in Adnroid

So I would run to action for a button tap? One for Android and one for IOS? Would I put this in the beginning of each action?

Apperyio.getTargetPlatform()

To put it simly I want to have apdf open when the user taps a button on the phone. For the IOS phone it would just open a window with the following code.

codewindow.open('https://api.appery.io/rest/1/db/files/527be05fe4b0157abfe953f4/6834ad8c-3f4a-40bc-a2d9-5078814e9e13.MI-3120_Family_of_Synthesized_Signal_Sources.pdf', '_blank','EnableViewPortScale=yes');/code

Or, if it is an Android I would need it to download the pdf.

Could you provide a sample script that would handle all those options so I could see how it lays out in one continuous script?

And please do not direct me to the phone gap documentation. It hasn't helped me very much.

Thanks.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Open pdfs from database in Adnroid

Hi Jay,

Then check:preif (Apperyio.getTargetPlatform() === "Android"){
var fileTransfer = new FileTransfer();

fileTransfer.download(
url,
filePath,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
);
} else {
window.open(url, '_blank','EnableViewPortScale=yes');
}/preWhere:

'url' is a link to a file you need to download
'filePath' is a link to a file where it will be saved (for Android).

Jay6395558
Posts: 0
Joined: Thu Nov 07, 2013 8:17 pm

Open pdfs from database in Adnroid

Katya,

Does the 'url' need to be from an external website or can it be from the Appery database? Does it matter? For example...

codehttp://www.mitechnologies.com/images/catalog/Instruments%20&%20Products/MI-3320_Family_of_Coaxial_and_Waveguide_Multiplexers.pdf/code

codehttps://api.appery.io/rest/1/db/files/527be05fe4b0157abfe953f4/ea74cb89-ace4-47b6-9c34-2e6a2e052f76.MI-3320_Family_of_Coaxial_and_Waveguide_Multiplexers.pdf/code

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Open pdfs from database in Adnroid

Hello Jay,

It can be either link to external site or direct link to a file in Appery.io database: http://devcenter.appery.io/documentat...

Jay6395558
Posts: 0
Joined: Thu Nov 07, 2013 8:17 pm

Open pdfs from database in Adnroid

Katya,

So, if I understand your script this is how I created it for a pdf I want to have downloaded to the phone after being called from my database. Does this look correct to you?

precodeif (Apperyio.getTargetPlatform() === "Android"){
var fileTransfer = new FileTransfer();
fileTransfer.download(
url = 'https://api.appery.io/rest/1/db/files/527be05fe4b0157abfe953f4/72dfba43-c860-46b6-b86b-1d2f64b38531.MI-15_Family_of_Standard_Gain_Dipoles.pdf',
filePath = "file://sdcard/sdcard0/download/MI-15_Family_of_Standard_Gain_Dipoles.pdf",
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
);
} else {
window.open(url, '_blank','EnableViewPortScale=yes');
}/code/pre

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Open pdfs from database in Adnroid

Hi Jay,

No. Should be like this:prevar url = 'https://api.appery.io/rest/1/db/files/527be05fe4b0157abfe953f4/72dfba43-c860-46b6-b86b-1d2f64b38531.MI-15_Family_of_Standard_Gain_Dipoles.pdf',
var filePath = "file://sdcard/sdcard0/download/MI-15_Family_of_Standard_Gain_Dipoles.pdf",

if (Apperyio.getTargetPlatform() === "Android"){
var fileTransfer = new FileTransfer();
fileTransfer.download(
url,
filePath,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
);
} else {
window.open(url, '_blank','EnableViewPortScale=yes');
}/pre

Jay6395558
Posts: 0
Joined: Thu Nov 07, 2013 8:17 pm

Open pdfs from database in Adnroid

This did not work. When testing the app after building the .apk I get this result when trying to access the pdf.

Image

The code I used to prompt this result was...

precodevar url = 'https://api.appery.io/rest/1/db/files/527be05fe4b0157abfe953f4/72dfba43-c860-46b6-b86b-1d2f64b38531.MI-15_Family_of_Standard_Gain_Dipoles.pdf',

var filePath = "file://sdcard/sdcard0/download/MI-15_Family_of_Standard_Gain_Dipoles.pdf",

if (Apperyio.getTargetPlatform() === "Android"){

var fileTransfer = new FileTransfer();

fileTransfer.download(

url,

filePath,

function(entry) {

console.log("download complete: " + entry.fullPath);

},

function(error) {

console.log("download error source " + error.source);

console.log("download error target " + error.target);

console.log("upload error code" + error.code);

}

);

} else {

window.open(url, '_blank','EnableViewPortScale=yes');

}/code
/pre

Return to “Issues”