Android: How to get UAProf value in Android SDK?

2k views Asked by At

I am currently developing an Android application with a WebView component which displays a website that is designed for mobile phones and thus the x-wap-profile header must be sent to the site in order to resize the CSS and the images.

Can anyone help me find the UAProf device setting?

I've conducted a lot of searching, with no success.

Any help will be greatly appreciated.

Thanks in advance.

2

There are 2 answers

1
CommonsWare On BEST ANSWER

Can anyone help me find the UAProf device setting?

There is no "UAProf device setting".

You are welcome to use the version of loadUrl() where you supply your own set of headers to include your desired header. Note that this was added in API Level 8 (a.k.a., Android 2.2) -- AFAIK, prior versions of Android had no options for supplying custom headers.

You are also welcome to set your user agent string via WebSettings, if the Web site in question will use that instead of your desired header.

2
Mark Butler On

UAProf is meant to work as follows: when a device sends a HTTP request to a server, it sends some addition accept headers. One of these headers provide a link to the UAProf profile for that device, which is located on a server, normally at the device manufacturer, or possibly at the network operator. A UAProf can also, optionally, send overrides as part of the accept headers, although I have never seen that happen in the wild, but admittedly it is a long time since I worked on UAProf.

So in your case, what you need to do is either send the x-wap-profile heading pointing to a real UAProf profile, or if no such profile exists, you need to write one. I haven't used the WebView component - I do server side java - but it is possible to set the x-wap-profile like this if you are using a HttpURLConnection:

    HttpURLConnection urlconn = (HttpURLConnection) url.openConnection();
    urlconn.setRequestProperty("X-Wap-Profile", 
         "http://wap.samsungmobile.com/uaprof/GT-I8190.xml");

You can find more UAProf profiles at the Open Mobile Alliance validator site.

Reviewing the Android source code it seems there is no way to access the UAProf profile associated with a device from within an Android application. However Android does have a separate API, android.content, that supplies applications with information about the device - here's an example. Unfortunately, once you have got the screen geometry, you would need to convert this into a profile, which will take a bit of work.

The other solution is if you could get the device name from Android, then you could cross reference that against a database of profiles that maps device names onto profiles. I don't think such a database already exists, but it might be possible to construct one. One starting point is the list of profiles on the OMA validator site database. Unfortunately this is out of date as I haven't worked on UAProf for a number of years, but the code I used to generate the list is available in DELI, the Java UAProf library I wrote. It queries Google to find recent profiles, but Google do tend to update their web page design, so the scraper it uses may be broken.

Before you do this, you want to check if the website will use the UAProf information - maybe you are writing the site, in which case it will fine - but for third party sites, I suspect many do not use UAProf, because the quality of UAProf profiles is very variable, if they use device information at all, they may just detect the user agent string, then look it up in a curated profile collection like WURFL or a similar paid solution.