0

Howto determine if mobile device.

asked 2016-09-30 05:24:52 +0800

dormitionskete gravatar image dormitionskete
15 4

execution.isBrowser("mobile") seems to be deprecated.

Is there a better way to determine if the user is using a mobile device?

delete flag offensive retag edit

5 Answers

Sort by ยป oldest newest most voted
1

answered 2016-09-30 07:48:12 +0800

Darksu gravatar image Darksu
1991 1 4

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

link publish delete flag offensive edit
0

answered 2016-09-30 18:03:05 +0800

dormitionskete gravatar image dormitionskete
15 4

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);
link publish delete flag offensive edit
0

answered 2016-10-01 12:21:14 +0800

Darksu gravatar image Darksu
1991 1 4

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

link publish delete flag offensive edit
0

answered 2016-10-03 06:57:05 +0800

dormitionskete gravatar image dormitionskete
15 4

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?

link publish delete flag offensive edit
0

answered 2016-10-03 08:58:20 +0800

Darksu gravatar image Darksu
1991 1 4

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

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2016-09-30 05:24:52 +0800

Seen: 32 times

Last updated: Oct 03 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More