Question

I'm implementing a browser for Android. What I need to do is to find out whether the website I'm visiting has a mobile version or not. If the mobile version is available I should be able to redirect the webpage to the mobile version. I also have an option for the user to decide whether or not to redirect the webpage to the mobile version. For example if the user prefers to keep the option Redirect to Mobile Ver. "On" then I should redirect him from ex.www.google.com -> m.google.com if he selects otherwise then I should let him visit www.google.com.

Source: There are several ways you can redirect requests to the mobile version of your web site, using server-side redirects. Most often, this is done by "sniffing" the User Agent string provided by the web browser. To determine whether to serve a mobile version of your site, you should simply look for the "mobile" string in the User Agent, which matches a wide variety of mobile devices. If necessary, you can also identify the specific operating system in the User Agent string (such as "Android 2.1").

I need the code for Android to perform sniffing and identifying the website.

Hope you can help me with this. Thank you for your time!

Was it helpful?

Solution

Actually, this conversion should usually be done by the web page, not yourself.

The web page detects whether or not you are a mobile based on your User Agent String, in this case, if you contain "Mobile" or "Android" in your User Agent.

If you're designing a web browser you should usually allow your users to choose between a desktop web browser UA string and a typical Android UA string, perhaps if you pull the devices WebView and get it's default UA string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top