JAVA class for device-detection? (JAVA, not JS.....;-)

don’t know where to post this… why is there no JAVA forum (there is PHP, python, etc… why not JAVA???)

is there a java class for device-detection like this PHP class?

using the tradicional CSS media queries, I find that some phones are so large that in landscape they load the CSS for tablets, and some tablets are so small that when you display them portrait they load the CSS for phones…

this PHP class for detecting device is much more reliable than the CSS media queries (& and I have tested it extensively on a website I did in PHP and so far it has never failed…) I would like to know if there is a class like this in java…

(theoretically this class could be re-written in java, I suppose, but I don’t know if I could do that…:wink:
although I would enjoy the challenge, it would take me far too long…)

lines like

return self::$phoneDevices;

would stump me…:wink:

(this is not the same as

return $phoneDevices;

I assume?? :wink:

(and, just out of curiosity: would re-writing this class in java violate the license of this PHP class Mobile_Detect?)

thank you…

None that I know of. I have implemented the Java version of UA-Parser and it can be quite heavy and completely parses through everything in the UA.

This might be what you’re after though. It looks fairly dated.

Alternatively, you could just write your own simple regex.

Browser detection using the user agent

It’s under the MIT License. So yes.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:


I have asked this many times. I gave up. lol The JVM is quite large and encompasses more than a few languages.

thank you Mawburn…

I dl’d and compiled the class you linked to… (UAgentInfo.java) will play w/it a bit…

(essentially I need to distinguish betw computer, tablet, & phone… will see what I can do w/this class…)
(have limited access to internet now, can’t do extensive searching…)

thanks again…

1 Like

oh man… I don’t know what I’m doing wrong… haven’t imported classes and stuff for a while…

this is for a JSP, so I did:

<%@ page import=“com.handinteractive.mobile.UAgentInfo”%>

then, just for testing, I tried these stmts:

<% 

    
    out.println(deviceIphone);
    
/*    
    if(detectWebOSTablet() ) {
        out.println("tablet");
    }
*/

%>    

on both of these stmts get a “cannot resolve” error…

what am I missing? the class is in

…/webapps//WEB-INF/classes/com/handinteractive/mobile/

JSP using this class is at root of webapp…

I even restarted Tomcat after I had compiled the class…

why can’t the JSP find this var (deviceIphone) or the method (detectWebOSTablet) inside class UAgentInfo???

since inside the class, right above the class decl, it says

package com.handinteractive.mobile;

I tried importing the class thus

<%@ page import=“UAgentInfo”%>

but get same error…

I also tried importing thus:

<%@ page import=“com.handinteractive.mobile.*”%>

same thing…

thank you…

The class should be in your src folder, not WEB-INF and compile it with your project. Just make sure you change the package name to wherever you put it.

So if you want to keep that package name you put it:

/src/com/handinteractive/mobile/UAgentInfo

Then <%@ page import="com.handinteractive.mobile.*" %> should work.


Generally it’s considered bad practice to use scriplets in the page like what you’re trying to do. It should all be done by the Servlet and parsed by the template engine like JSTL or Thymeleaf.

the class should be in my src folder??? say what? the compiled class?

hmmm…

(I don’t compile my project… it’s just JSP’s, personal site, fairly small… Tomcat compiles them for me…:wink:
I compiled this class myself “by hand” on the shell, the old-fashioned way (using javac…:wink:

thank you…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.