Before I had just one controller where I was able to load my webview, and set a custom user agent for it and it would work completely fine.
Now, my first controller (the index), opens another controller containing my webview. When this new controller that I've just opened from my index controller loads, it sets the webview's useragent to this:
var webview = $.webview; var newUserAgent = Titanium.userAgent + " " + webview.userAgent; //webview.setUserAgent(newUserAgent); $.webview.url = "http:/mytestsite.com"; //blocked actual site name on here for privacy reasonsThe webview is completely blank on Android, website shows up on iOS. Why? Here's my very simple code executed from my index.js file to open the new controller containing the web view:
var win = $.win; var theTest = Alloy.createController('web').getView(); theTest.open(); win.close(); }Here's my index controller Alloy XML:
<Alloy> <Window title="Index Controller"> </Window> </Alloy>Here's my new controller's Alloy XML:
<Alloy> <Window id="webwin" backgroundColor="white" layout="vertical" title="Webview Controller"> <View id="view_webview" width="100%" height="100%"> <WebView id="webview" width="100%" height="100%" /> </View> </Window> </Alloy>Now again, this worked perfectly before on Android when I was only using the index controller. This also now currently works on iOS. But now on Android, now that I'm opening a new controller up rather than executing this directly in the index, the webview is completely blank. White. I have no idea why.
If I try to change the URL with a button, still white. So it's definitely the user agent messing this up on Android.
I then thought Titanium was bugging up so I might have to use a module to change the user agent on android to get it to work. Nope: https://github.com/harukazepc/TiWebViewUserAgent/
Not only is that module 3 years old but there are no .zip files anywhere there for Android (unless someone can correct me but I couldn't find one).
Even so even if I did get that module to work I am confident Titanium will break the webview still if I try to change the user agent either way on Android.
Why does this only happen on android when I try to change the user agent of a webview ONLY AFTER opening a new controller containing that webview? If the webview is in the index controller it works fine, if not..bam. (on iOS works though)
What can I do to fix this?
I tried this in a completely new app too, same problem. I even set the url to http://www.google.com, blank page. Works fine in iOS though.
Tested in Nexus 4 Android Lollipop 5.0 (webview blank), and iPhone 5 iOS 8.1 (works).