Created
October 6, 2011 22:32
-
-
Save jonalter/1268892 to your computer and use it in GitHub Desktop.
Android: download pdf and save it to the sdcard
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
| 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