This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the Screen size of requesting mobile device

 
pradeep u nair
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends
can anybody tell me how to get the screen size of the mobile device that makes a request for some application on some connected server.Also can the device type be retrieved.
Please help
Pradeep
 
dema rogatkin
Ranch Hand
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is JavaScript working for you?
 
pradeep u nair
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi dema
thnx for your interest in this question.
by the way we are working on the mobile wtk22 emulator.on j2me. i want to get the screen size of the requesting device so that i can place the images i am downloading from a servlet accordingly.
Do you know of any such means.
pls do reply
Pradeep
 
dema rogatkin
Ranch Hand
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How this device requests? Let's say it uses browser, then you can analyze user agent field, like:
Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320)
If your requester is AWT program then you can use:
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 
pradeep u nair
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your answer.i think it works properly.i have to check it with other emulator screens. thnx
 
Rashid Mayes
Ranch Hand
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IS your question specific to J2ME devices? If so, the screen size may not be included in the user agent. You may be able to use the uaprof to determin screen size.

A better solution is for the application to tell the server the dimensions it needs.

You can use the getHeight and getWidth methods of canvas and pass the values to the server via get or post.

i.e. http://myserver/getimage?imageid=x&height=H&width=W

-rashid
www.hostj2me.com
 
pradeep u nair
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rasheed
i got the screen size and width with the same methods before itself when dema helped me. i was abt to post it in the reply but thats when i saw your reply.
thnx anyway.
I used a form and the parameters like getWidth and getHeight of the form gave me the correct size of the form and hence the display area.the thing is i tried with an emulator.got to try it with a real phone.
Thnx
Pradeep
 
Punit Raizada
Ranch Hand
Posts: 156
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its great your code is working for you.

Just to categorize a few of the options available.

1) If a MIDlet makes a request to the server, its always better to add a property to the request like screen width and screen height. This way the server can read the HTTP headers of the request and determine what sort of content to send out.

2)A combination of User Agent and/or HTTP_X_WAP_PROFILE (or HTTP_PROFILE) headers can be used by the server to determine the screen dimensions of the mobile device.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic