My application often used WebView as core. My websites are deployed in 3 different host for increase the availability of service. How to handle switching the websites efficiently if one of them is down or cannot reach. Assume the websites url are url1, url2 and url3 respectively. For Example if webview.loadUrl(url1); bring any error result, It should switch to another.
Thanks
Android WebView onReceivedError()
may be will help you.
when you use onReceivedError to handle your problem, you could switch you url in the override function.
Related
I usually don't like to post questions because I would rather figure things out myself, but I am ready to pull my hair out with this one. I am trying to interface with a Sony IP Camera using Java. One of the products of the company I work for uses a Sony IP camera (IPela EP550). I have been tasked with writing the new interface. I can connect to the stream using the VLC ActiveX embedded control, but I can't manipulate the PTZ of the camera from in Java. If I type: "http://xxx.xxx.xxx.xxx/command/ptzf.cgi?Move=left,0" in a web browser it will move, but I have tried every bit of code I can find with Google to get it to move with no success. This last thing I tried (because a page on Oracle said all I should have to do is open the connection):
URL url1 = new URL("http://xxx.xxx.xxx.xxx/command/ptzf.cgi?Move=left,0&t="+new Date().getTime());
HttpURLConnection con = (HttpURLConnection)url1.openConnection();
Any help will be appreciated. Thank you.
Joe
Check out whether the camera needs login.
type the url in the browser, get HTTP request header and put header data into your code!
I figured out how to do this. I am posting the solution in case anybody is looking to fix a similar problem. I took the basic idea in this Dr. Dobbs article and used it to get movement from the camera. I don't yet know why I can't get the camera to respond with URLConnection and HttpURLConnection, but using a Socket and PrintWriter to specifically print the GET request to the socket.
Sorry for the vagueness of my questions here, but I wanted to know if it was possible to login into this website https://oyster.tfl.gov.uk/oyster/entry.do through an a native phone app?
I've seen many apps which access data for the Oyster Card but there is no API for them to access this data and can only think they've logged into the website using the users details then extracting the necessary text to display within their app.
Here is a sample app alongside what the actual website looks like once logged in;
Sure it is, here is an example using WebView:
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://oyster.tfl.gov.uk/oyster/entry.do");
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:document.getElementsByName('j_username')[0].value = '"+ausername+"'");
view.loadUrl("javascript:document.getElementsByName('j_password')[0].value = '"+apassword+"'");
view.loadUrl("javascript:document.forms[0].submit()");
}
});
This will show the common desktop version of the website but if you want a dedicated app for the site, it would be preferable with some sort of API for the site. Without an API, you are left with either the common desktop website, or DOM manipulation of the received html using regular HTTP requests.
I just implemented the ad-network, Leadbolt, into my android application. Im using the HTML Banner as my adtype. And I would like some kind of fallback solution if Leadbolt fails to load use Admob instead etc.
Bringing Leadbolt html ads is done via a webview and you pass in a URL to the webview and the ad is shown within.
This is the code:
wv.getSettings().setJavaScriptEnabled(true);
wv.setBackgroundColor(Color.TRANSPARENT);
String html = "MY_ID";
wv.loadData(html, "text/html", "utf-8");
I also have set my Webview (wv) set on: setWebViewClient, so I get callbacks but even if I dont have any internet connection I get the callback OnPageFinished so im unable to se if my ad has loaded or what has been done.
Does anyone have any advice how to do this, to help me with a fallback solution?
Thanks!
Check your www.adwhirl.com
With the SDK and homepage you can create new "Apps" with a fallback hierarchy. All you need to do is, create a custom event on adwhirl, implement the method for calling your ads on leadbolt add your publisher id to admob settings and set up the fallback hierarchy.
Hope this helps. Good luck.
I am new to CQ 5 Mobile Application Development what I want to achieve is,
When a mobile device send the request to the page it captures the attributes of mobile like mobile browser, mobile browser version, mobile OS and mobile OS version.
I want to LOG this information and in later stage use this to categorize them in different Device Group and render different components in different device groups.
Note I have already went through some of these links
CQ5 Mobile Development Docs
http://www.cognifide.com/blogs/cq/adobe-cq-5-5-mobile-improvements/
http://wurfl.sourceforge.net/help_doc.php
I have tried this code which throws Null Pointer Exception, since device has null value.
Correct me if I am doing wrong somewhere
SlingHttpServletRequest slingRequest = this.request.getSlingRequest();
Device device = slingRequest.adaptTo(Device.class);
Map<String, String> deviceAttributes = device.getAttributes();
LOG.info("Request is sent from Device with OS"+deviceAttributes.get("device_os"));
Here is the way I am testing this code, whenever a request is sent to the page which has this component which logs the attributes of the mobile device from one of the emulator, I check my LOG Files that
Please help me out if I am going wrong in the code or method to get the mobile device's attributes. Please let me know if you need more details on this.
Regards,
Yash
Hi Here is the Stack Trace for this :
Caused by: org.apache.sling.api.SlingException: An exception occurred processing JSP page /apps/companyname/components/content/mobilebreadcrum/mobilebreadcrum.jsp at line 5
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:571)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:496)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:448)
at org.apache.sling.scripting.jsp.JspServletWrapperAdapter.service(JspServletWrapperAdapter.java:59)
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:173)
at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:84)
at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:388)
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:358)
... 147 more Caused by: javax.el.ELException: Error reading 'modelName' on type com.companyname.www.components.content.mobilebreadcrumb.MobileBreadCrum
at javax.el.BeanELResolver.getValue(BeanELResolver.java:66)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
at org.apache.el.parser.AstValue.getValue(AstValue.java:97)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.sling.scripting.jsp.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:923)
at org.apache.jsp.apps.companyname.components.content.mobilebreadcrum.mobilebreadcrum_jsp._jspService(mobilebreadcrum_jsp.java:160)
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
... 152 more Caused by: java.lang.NullPointerException
at com.companyname.www.components.content.mobilebreadcrumb.MobileBreadCrum.getModelName(MobileBreadCrum.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
... 160 more
The JSP Code is :
<%#include file="/apps/companyname/components/global.jsp"%><ct:component
className="com.companyname.www.components.content.mobilebreadcrumb.MobileBreadCrum"
name="mobilebreadcrum" />${mobilebreadcrum.modelName}
The Java Code is:
public String getModelName() {
SlingHttpServletRequest slingRequest = this.request.getSlingRequest();
String resourceType = slingRequest.getResource().getResourceType();
String resourceSuperType = slingRequest.getResource().getResourceSuperType();
LOG.info("RESOURCE TYPE:"+resourceType);
LOG.info("RESOURCE SUPER TYPE:"+resourceSuperType);
Device device = request.getCurrentPage().adaptTo(Device.class);
device.getAttributes();
return modelName;
}
Please let me know if you want anything else
Regards,
Yash
Could you please go to /system/console/adapters and make sure that there is appropriate adapter SlingHttpServletRequest → Device?
I'd start diagnosis from there. In my case corresponding row looks like this:
Adaptable Class: org.apache.sling.api.SlingHttpServletRequest
Adapter Class: com.day.cq.wcm.mobile.api.device.DeviceGroup, com.day.cq.wcm.mobile.api.device.DeviceGroupList, com.day.cq.wcm.mobile.api.device.Device
Providing bundle: com.day.cq.wcm.cq-wcm-mobile-core (190)
Thanks,
Max.
To do this u should use real device, not an emulator. To detect a device CQ looks at user-agent data in the request, so when u open a page on desktop browser u send request with not-a-mobile device user-agent data. To test this feature u can use something like user agent switcher (eg for chrome), but in that case CQ will not use and draw an emulator wrapper cause it will assume that u use a mobile device.
Now I think how to combine right user-agent and drawing an emulator on desktop. Will post by results.
thinking a step above, if you are able to fix this issue how you gonna serve requests? will you always serve requests from publish Aem server or you want to utilize Dispatcher caching?
As your code is identifying device on server side, i doubt you would be able to leverage dispatcher caching. can you think of identifying device on apache level and add selectors in request.
eg. if request if coming from iphone5, then write a rewrite rule on apache to check User agent header and add a selector
http://somesite.com/my/page/url.html to http://somesite.com/my/page/url.iphone.html
if request coming from ipad then add other selector
http://somesite.com/my/page/url.ipad.html
Dispatcher will create different cache for different selectors and will start serving pages from cache.
In your component, you can implement different views for different selector.
Its just a thought, please rethink ...
I have an existing web app which uses Struts for the forward-action...
I am trying to create a mobile version (mainly the UI design will be different) of this existing web app.
Now this app is using Struts 2 for the forward-action thing..
My question is can I extend this Struts XML to redirect based on desktop/mobile..
e.g. Let's say I have desktop.jsp and mobile.jsp...Now I detect where the user is coming from at a server level and have that info in the session..Can I update my stuts-config XML such that the only thing I need to change would be the "forward" JSP URL based on where the user is coming from?
I am looking at no change to the Action...only the forward URL for the JSP.
Please note that this question is not about "how to detect", but more about what approach to take once we have detected the browser and have that info from the server..
Thank you.
Better option is always to add a Filter here . and rest how to detect you know it.
Track all the request check for the header to find out if its coming from mobile ? and serve request according to it.
you can forward the request to another action which will handle the mobile specific data to load and maybe to have different results. One result pointing to desktop.jsp other pointing to the mobile.jsp.
sample:
public String execute(){
if(isMobile())
return "mobile";
else return "desktop";
}