Created
September 14, 2011 00:07
-
-
Save jonalter/1215524 to your computer and use it in GitHub Desktop.
Android: open pdf with external pdf reader
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
| // Must have a pdf reader app installed, maybe Adobe Reader, maybe something else | |
| var win = Ti.UI.createWindow({ | |
| navBarHidden: true, | |
| backgroundColor: 'blue' | |
| }); | |
| win.open(); | |
| var button = Ti.UI.createButton({ | |
| title: 'Get PDF', | |
| height: 50, | |
| width: 200, | |
| top: 20 | |
| }); | |
| win.add(button); | |
| button.addEventListener('click', function(e) { | |
| var xhr = Ti.Network.createHTTPClient(); | |
| xhr.onload = function() { | |
| var f = Ti.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory,"test.pdf"); | |
| f.write(this.responseData); | |
| var intent = Ti.Android.createIntent({ | |
| action : Ti.Android.ACTION_VIEW, | |
| type : 'application/pdf', | |
| data : f.getNativePath() | |
| }); | |
| Ti.Android.currentActivity.startActivity(intent); | |
| }; | |
| xhr.open("GET", "http://www.appcelerator.com/assets/The_iPad_App_Wave.pdf"); | |
| xhr.send(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment