Page 2 of 3

Open pdfs from database in Adnroid

Posted: Mon Jun 02, 2014 1:02 pm
by Jay6395558

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


Open pdfs from database in Adnroid

Posted: Mon Jun 02, 2014 2:39 pm
by Jay6395558

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?


Open pdfs from database in Adnroid

Posted: Tue Jun 03, 2014 6:11 am
by Evgene Karachevtsev

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...


Open pdfs from database in Adnroid

Posted: Tue Jun 03, 2014 2:08 pm
by Jay6395558

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.


Open pdfs from database in Adnroid

Posted: Wed Jun 04, 2014 3:59 pm
by Kateryna Grynko

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).


Open pdfs from database in Adnroid

Posted: Wed Jun 04, 2014 8:09 pm
by Jay6395558

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


Open pdfs from database in Adnroid

Posted: Thu Jun 05, 2014 10:26 am
by Evgene Karachevtsev

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...


Open pdfs from database in Adnroid

Posted: Fri Jun 06, 2014 2:54 pm
by Jay6395558

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


Open pdfs from database in Adnroid

Posted: Fri Jun 06, 2014 7:14 pm
by Kateryna Grynko

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


Open pdfs from database in Adnroid

Posted: Tue Jun 10, 2014 2:43 pm
by Jay6395558

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