views:

83

answers:

1

I'm trying to find the user agent of a blackberry so I can set it when I make a http connection. On blackberries that are version 4.7+ I call System.getProperty("browser.useragent") and I get the correct value. On earlier versions this returns null. Is there another way to get the user agent?

A: 

try this

    private static String getUserAgent() {
         String userAgent = "Blackberry" + DeviceInfo.getDeviceName() + "/" +
         getOsVersion() + " Profile/" + System.getProperty(
         "microedition.profiles" ) + " Configuration/" + System.getProperty(
         "microedition.configuration" ) + " VendorID/" +
         Branding.getVendorId();
        return userAgent;// URLencode(userAgent);

}
    public static String getOsVersion(){
        String version = "";
        ApplicationDescriptor[] ad = ApplicationManager.getApplicationManager()
        .getVisibleApplications();
        for (int i = 0; i < ad.length; i++) {
            if (ad[i].getModuleName().trim().equalsIgnoreCase(
                    "net_rim_bb_ribbon_app")) {
                version = ad[i].getVersion();
                break;
            }
        }
        return version;
    }
Vivart