Hi all ,
I am using 2.1.1 titanium sdk and 2.3.3 android sdk , I am trying to show the pdf . But its saying that file path not valid .. My pdf is located in the resource folder .
var f = Ti.Filesystem.getFile('file.pdf'); Ti.Android.currentActivity.startActivity(Ti.Android.createIntent({ action: Ti.Android.ACTION_VIEW, type: 'application/pdf', data: f.getNativePath() }));
5 Answers
Seriously? You don't see the problem here?
var f = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "file.pdf");
In android, you can't access a resource file from an external reader. So, you need to copy to a temporary folder.
This function will do the job for you
function openPdf(file){ var appFilePath = Ti.Filesystem.resourcesDirectory + '/' + file; var appFile = Ti.Filesystem.getFile(appFilePath); var tmpFile = undefined, newPath = undefined; if (Ti.Filesystem.isExternalStoragePresent()) { tmpFile = Ti.Filesystem.createTempFile(); newPath = tmpFile.getParent().nativePath +'/' + file; if(!Ti.Filesystem.getFile(newPath).exists()){ tmpFile.move(newPath); tmpFile = Ti.Filesystem.getFile(newPath); tmpFile.write(appFile.read()); }else{ tmpFile.deleteFile(); tmpFile = Ti.Filesystem.getFile(newPath); } } else { Ti.API.error('No external storage present'); } if (tmpFile) { var intent = Ti.Android.createIntent({ action: Ti.Android.ACTION_VIEW, type: "application/pdf", data: tmpFile.nativePath }); try { Ti.Android.currentActivity.startActivity(intent); } catch(e) { Ti.API.debug(e); alert('PDF reader not found'); } return tmpFile; } }
We're having a similar experience. The intent runs/works fine on our old Motorola Bravo, but when running on our new Nexus we get a "The document path is not valid."
Strangest thing.
Boost Media,
Some information on the problem you are having and why.
I have no idea what to do about this.
Your Answer
Think you can help? Login to answer this question!