Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

by Administrator on ‎08-10-2010 12:02 PM - edited on ‎04-24-2013 10:24 AM by BlackBerry Development Advisor (93,326 Views)

Every HTTP request for a web page made by the BlackBerry® Browser, or an embedded web view (BrowserField) contains a collection of HTTP headers. One of these headers is the User Agent. The User Agent header contains information that identifies various characteristics about the BlackBerry device making the web request. This article presents an overview of the User Agent and provides examples on how you use this information to give your BlackBerry device users an optimal mobile browsing experience based on which BlackBerry device they are using.

 

 

User Agent in BlackBerry 10

 

The format of the User Agent used by BlackBerry® 10 is similar to the following:

 

Mozilla/5.0 (BB10; <Device Type>) AppleWebKit/537.10+ (KHTML, like Gecko) Version/<BB Version #> Mobile Safari/537.10+

 

As shown in this specific example, the user agent identifies three important pieces of information:

  • The device type of the BlackBerry smartphone being used to make the web request can be found in the placeholder identified by <Device Type>.

For the BlackBerry Z10 device, this will be "Touch"

For the BlackBerry Q10 device, this will be "Kbd"

 

  • The OS version number of the BlackBerry smartphone is identified by the placeholder <BB Version #> (e.g. 10.0.9.1675).
  • The rendering engine used to power the device is WebKit.

 

 

User Agent in BlackBerry Tablet OS

 

The format of the user agent of the BlackBerry® Tablet OS is similar to the following:

 Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.0.0; en-US) AppleWebKit/535.8+ (KHTML, like Gecko) Version/7.2.0.0 Safari/535.8+

 

User Agent in BlackBerry 6 and BlackBerry 7

 

The format of the User Agent used by BlackBerry® 6 and BlackBerry® 7 is similar to the following:

 

Mozilla/5.0 (BlackBerry; U; BlackBerry AAAA; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/X.X.X.X Mobile Safari/534.11+

 

As shown in this specific example, the user agent identifies three important pieces of information:

  • The model number of the BlackBerry smartphone being used to make the web request can be found in the placeholder identified by AAAA (e.g. 9900 or 9800).
  • The model number of the BlackBerry smartphone is identified by the placeholder X.X.X.X (e.g. 6.0.0.141 or 7.0.0.1).
  • The rendering engine used to power the device is WebKit.

 

 

User Agent in BlackBerry Device Software 4.2 to 5.0

 

The format of the user agent used by BlackBerry® Device Software 4.2 to 5.0 is similar to the following:

 

BlackBerry9000/5.0.0.93 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/179

 

As shown in this specific example, the user agent identifies three important pieces of information:

  • The model number of the BlackBerry smartphone being used to make the web request is 9000.
  • The version of the BlackBerry® Device Software installed on the BlackBerry smartphone is 5.0.0.93.
  • The rendering engine used to power the device is MIDP-based (Java®).

 

 

Evolution of the BlackBerry web platform rendering engine

 

The underlying web engine that powers the BlackBerry web platform has evolved over time.  As new releases to the BlackBerry device software are published, so have they included improvements and advancements to the web engine.  As the user experience can be different for web content rendered by different rendering engines, it is important for developers to have a clear understanding of which engines are used on each platform, and for each type of web view.

 

    Web View objects
OS Browser application BrowserField2 RenderingApplication QnxWebStageView
Tablet OS 1.x - 2.x WebKit N/A N/A WebKit
BlackBerry 7 WebKit WebKit MIDP v1 N/A
BlackBerry 6 WebKit WebKit MIDP v1 N/A
5.0 MIDP v2 MIDP v2 MIDP v1 N/A
4.7 MIDP v2 N/A MIDP v1 N/A
4.6 MIDP v2 N/A MIDP v1 N/A
4.5 MIDP v1 N/A MIDP v1 N/A

 

Note: RenderingApplication is the legacy web view object. Developers are highly encouraged to use BrowserField2 instead for OS 5.0, BlackBerry 6 and 7 development as it offers access to more advanced web rendering engines (WebKit or MIDP v2).

 

  

How to detect the BlackBerry web platform

There are many ways your web content can read and evaluate the user agent header. Below you will find examples that demonstrate how to use various web technologies to implement this capability in your web site. Choose whichever technology suits your web site best (for example, if your existing web site is written in PHP, see the PHP sample).

 

Note: To detect the BlackBerry web platform for the BlackBerry 10 device, replace the search term "BlackBerry" with "BB10" or "blackberry" with "bb10" in the samples below.

 

Detecting the BlackBerry web platform in BlackBerry Device Software 6.0 using JavaScript®:

When using Javascript®, the following script can be executed inline or made into a function and called when the page’s onload event occurs:

 

 

<script type="text/javascript">   
var ua = navigator.userAgent;
var url = "http://optimizedmobile.yoursite.com/";
if (ua.indexOf("BlackBerry") >= 0)
{
if (ua.indexOf("WebKit") >= 0)
{
window.location = url;
}
}
</script>

 

Detecting the BlackBerry Browser in BlackBerry Device Software 6.0 using ASP:

When using ASP, a server-side scripting language, you read the user agent value from the ServerVariables collection:

 

 

<%
Dim userAgent
Dim url
userAgent = Request.ServerVariables("HTTP_USER_AGENT")
url = "http://optimizedmobile.yoursite.com/"

If InStr(LCase(userAgent), "blackberry") > 0 Then
If InStr(LCase(userAgent), "webkit") > 0 Then
Response.Redirect(url)
End If
End If
%>

 

Detecting the BlackBerry web platform in BlackBerry Device Software 6.0 using PHP:

When using PHP, a server-side scripting language, you read the user agent value from the _SERVER collection:

 

 

<?php
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$pos_blackberry = strrpos($ua, "blackberry");
$pos_webkit = strrpos($ua, "webkit");
$url = "http://optimizedmobile.yoursite.com/";

if (!($pos_blackberry === false))
{
if (!($pos_webkit === false))
{
header("Location: " . $url);
}
}
?>

 

Detecting the BlackBerry web platform in BlackBerry Device Software 6.0 using JSP:

When using JSP®, a server-side scripting language, you read the user agent value from the Request object: 

 

 

<%!
String detectBlackBerry(HttpServletRequest req)
{
String ua = req.getHeader("user-agent").toLowerCase();
String url = "";

if (ua.indexOf("blackberry") >= 0)
{
if (ua.indexOf("webkit") >= 0)
{
url = "http://optimizedmobile.yoursite.com/";
}
}
return url;
}
%>

<%
//Note: separate code block
String url = detectBlackBerry(request);
if (url.length() > 0)
{
response.sendRedirect(url);
}
%>

Detecting the browser transport

 

Connections made from the browser can be routed through a BlackBerry® Enterprise Server, the BlackBerry® Internet Service, a wireless service provider WAP gateway, or a W-iFi® network. For information on detecting the transport route, refer to Retrieve information about the BlackBerry Browser.

 

 

For more information about the BlackBerry browser, see:

Comments
by Developer on ‎04-28-2011 10:17 PM
Thank you for sharing . This will be very useful to a lot of developers.
by New Developer on ‎07-19-2011 03:56 AM

There must be other ways too, look at this page:

http://beta.whatsapp.com/ota/

 

Even with a faked User-Agent, e.g. from a Curve 8900, the site will notice that the request is not from a BlackBerry Browser:

WhatsApp for BlackBerry is available for download from this location. However, no valid BlackBerry browser has been detected. Please use your BlackBerry Browser when visiting this website...
...

For the record, we detected your browser as: BlackBerry8900/5.0.0.1067 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/124



by Administrator on ‎07-19-2011 01:35 PM

The profile and x-wap-profile headers can also be used to identify the BlackBerry Smartphone accessing a web site.  This is likely what the WhatsApp site is using.