Created
April 17, 2014 18:37
-
-
Save joshjensen/11003695 to your computer and use it in GitHub Desktop.
Android Intents PDF Viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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