2011-06-16 126 views
3

我們能夠通過調用黑莓System.getProperty( 「browser.useragent」)

System.getProperty獲得來自設備的用戶代理( 「browser.useragent」)

這種方法可用於OS 4.7 +

我只測試了一些黑莓模擬器:9530(OS 4.7),9800(OS 6.0.0)

它作爲一種魅力。

但據我所知,在真實的設備上,如果用戶更改黑莓瀏覽器,http請求服務器中的用戶代理將被改變。例如,一些黑莓設備使用Firefox瀏覽器。

因此,我想知道,如果瀏覽器設置在真實設備上發生變化,當我們調用System.getProperty(「browser.useragent」)時,返回值會發生變化嗎?

有沒有人在真實設備上測試過? 還是有人知道anwser。

回答

1

您可以通過創建一個應用程序來記錄或打印以顯示System.getProperty(「browser.useragent」)的值,然後在模擬器中進行註釋更改,從而在您選擇的模擬器中測試此功能。

+0

HI託德,感謝您的效應初探。那是一個好主意。我將需要測試它。 – 2011-08-05 02:49:46

0

這是一個例子:

public static String getSystemUserAgent(){ 
    String agent = ""; 
    if(System.getProperty("browser.useragent")!=null){ 
     agent = System.getProperty("browser.useragent"); 
    }else if(GI.isScreenSmall()){ 
     agent = "BlackBerry8100/4.5.0.180 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/215"; 
    }else{ 
     agent = "BlackBerry8300/4.2.2Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/107UP.Link/6.2.3.15.0"; 
    } 
    return agent; 
    } 

可以構建的UserAgent用這種方法

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

謝謝。我已經有了一個非常類似的代碼。 – 2012-03-16 03:37:36