Skip to content

Instantly share code, notes, and snippets.

@joshjensen
Created April 17, 2014 18:37
Show Gist options
  • Save joshjensen/11003695 to your computer and use it in GitHub Desktop.
Save joshjensen/11003695 to your computer and use it in GitHub Desktop.
Android Intents PDF Viewer
// Found here: https://developer.appcelerator.com/question/72361/open-pdf-file-on-android
try {
var f = Ti.Filesystem.getFile('your.pdf');
Ti.Android.currentActivity.startActivity(Ti.Android.createIntent({
action: Ti.Android.ACTION_VIEW,
type: 'application/pdf',
data: f.getNativePath()
}));
}
catch (err) {
var alertDialog = Titanium.UI.createAlertDialog({
title: 'No PDF Viewer',
message: 'We tried to open a PDF but failed. Do you want to search the marketplace for a PDF viewer?',
buttonNames: ['Yes','No'],
cancel: 1
});
alertDialog.show();
alertDialog.addEventListener('click', function(evt) {
if (evt.index == 0) {
Ti.Platform.openURL('http://search?q=pdf');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment