Search code examples
blackberryuser-agenthttpconnection

Find a blackberries user agent on 4.5


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?


Solution

  • try this

        private static String getUserAgent() {
             String userAgent = "Blackberry" + DeviceInfo.getDeviceName() + "/" +
             DeviceInfo.getSoftwareVersion() + " 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;
        }