Skip to content

Instantly share code, notes, and snippets.

@jonalter
Created September 14, 2011 00:07
Show Gist options
  • Select an option

  • Save jonalter/1215524 to your computer and use it in GitHub Desktop.

Select an option

Save jonalter/1215524 to your computer and use it in GitHub Desktop.
Android: open pdf with external pdf reader
// 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