-
FEATURED COMPONENTS
First time here? Check out the FAQ!
execution.isBrowser("mobile") seems to be deprecated.
Is there a better way to determine if the user is using a mobile device?
Hello dormitionskete,
You can try:
Executions.getCurrent().getBrowser("mobile")
Reference:
https://www.zkoss.org/javadoc/8.0.0/zk/org/zkoss/zk/ui/Execution.html
Best Regards,
Darksu
Thank you. That works. It seems a bit convoluted, though, in that in order to get the results into a boolean, you have to do something along the lines of what is below. Granted, a lot of this could be condensed into fewer lines.
Are there benefits to going through all this, as opposed to using the deprecated method?
Thank you again. I really appreciate it.
// Determine whether it is a mobile device.
boolean bMobile = false;
double d = 0.0;
try {
d = Executions.getCurrent().getBrowser("mobile");
} catch (Exception e) {
// throw
// e.printStackTrace();
}
// System.out.println("d: " + d);
if (d > 0.00) {
bMobile = true;
} else {
bMobile = false;
}
System.out.println("IsMobile: " + bMobile);
Hello dormitionskete,
If you do not mind, i did a small refinement to your code:
public static boolean checkMobile() {
boolean isMobile = false;
try {
isMobile = ( Executions.getCurrent().getBrowser("mobile") > 0) ? true : false;
} catch (Exception e) {
System.err.println(e.getMessage());
}
return isMobile;
}
Best Regards,
Darksu
Thank you very much. I do appreciate it. What I was trying to get at, though, was does the underlying code that determines whether it is mobile device more accurate using this new method, rather than the deprecated method?
Hello dormitionskete,
I would use the new method since the old one may stop to exist in a new version.
http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/deprecation/deprecation.html
Best Regards,
Darksu
Asked: 2016-09-30 05:24:52 +0800
Seen: 32 times
Last updated: Oct 03 '16