New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-23309] Android: Redirects are not being followed in HTTPClient #8043
Merged
Conversation
This file contains 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
Classic test code:- var OS_ANDROID = true;
function resourcePDF(e) {
openResourcePDF();
}
function urlPDF(e) {
openURLPDF();
}
function viewPDF(appfilepath) {
Ti.API.info("A:"+appfilepath);
if (OS_ANDROID) {
try {
Ti.Android.currentActivity.startActivity(Ti.Android.createIntent({
action : Ti.Android.ACTION_VIEW,
type : 'application/pdf',
data : appfilepath
}));
} catch(e) {
Ti.API.info('error trying to launch activity, e = ' + e);
alert('No PDF apps installed!');
}
} else {
docViewer = Ti.UI.iOS.createDocumentViewer({
url : appfilepath
});
docViewer.show();
}
}
function openResourcePDF() {
var appFile;
if (OS_ANDROID) {
//copy from app directory to SDCard (once)
var originalFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'pdf/sample.pdf');
appFile = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'sample.pdf');
if (appFile.exists() === false) {
appFile.write(originalFile.read());
}
} else {
appFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'pdf/sample.pdf');
}
var appfilepath = appFile.nativePath;
viewPDF(appfilepath);
}
function openURLPDF() {
var appFile;
if (OS_ANDROID) {
appFile = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'map.pdf');
} else {
appFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'map.pdf');
}
var appfilepath = appFile.nativePath;
//Check if file has been downloaded yet
if (appFile.exists() === false) {
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
Ti.API.info('status code ' + this.status);
Ti.API.info(this.responseData);
appFile.write(this.responseData);
viewPDF(appfilepath);
};
xhr.onerror = function() {
alert("Cannot retrieve PDF form web site");
};
xhr.timeout = 10000;
xhr.open("GET", "http://dev-cms-molpower.trafficmanager.net/ServiceProfileFileHandler.ashx?svc=CMI&file=FirstSchedule.pdf");
xhr.send();
} else {
viewPDF(appfilepath);
}
}
var win = Ti.UI.createWindow({
backgroundColor : 'black',
layout : 'vertical'
});
var button1 = Titanium.UI.createButton({
title: 'resourcePDF',
top: 30,
width: 100,
height: 50
});
var button2 = Titanium.UI.createButton({
title: 'urlPDF',
top: 100,
width: 100,
height: 50
});
button1.addEventListener('click',function(e)
{
Ti.API.info("Pressed");
resourcePDF();
});
win.add(button1);
button2.addEventListener('click',function(e)
{
Ti.API.info("Pressed");
urlPDF();
});
win.add(button2);
win.open(); |
Do note that you should have an app on Android that can open a PDF file for it to successfully launch and open the PDF. |
…or normal situations where it is from HTTP to HTTP or HTTPS to HTTPS.
Had to merge Master due to conflict. |
This was originally merged from tidev#8003 and added by m1ga. Due to merge conflicts, this code was moved and this commit is to put it back in place.
Merging |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
JIRA: https://jira.appcelerator.org/browse/TIMOB-23309
See ticket for test case.