有没有办法检测可用网络并直接在黑莓中连接? 我尝试过以下链接http://supportforums.blackberry.com/t5/Java-Development/What-Is-Network-API-alternative-for-legacy-OS/ta-p/614822,但收到以下错误
D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:8: package net.rim.device.api.io.http does not exist
[javac] import net.rim.device.api.io.http.HttpHeaders;
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:9: package net.rim.device.api.io.http does not exist
[javac] import net.rim.device.api.io.http.HttpProtocolConstants;
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:10: package net.rim.device.api.servicebook does not exist
[javac] import net.rim.device.api.servicebook.ServiceBook;
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:11: package net.rim.device.api.servicebook does not exist
[javac] import net.rim.device.api.servicebook.ServiceRecord;
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:12: package net.rim.device.api.system does not exist
[javac] import net.rim.device.api.system.Branding;
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:13: package net.rim.device.api.system does not exist
[javac] import net.rim.device.api.system.CoverageInfo;
[javac] ^
[javac] D:\sakina\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:14: package net.rim.device.api.system does not exist
[javac] import net.rim.device.api.system.DeviceInfo;
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:15: package net.rim.device.api.system does not exist
[javac] import net.rim.device.api.system.WLANInfo;
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:35: cannot find symbol
[javac] symbol : class ServiceRecord
[javac] location: class HttpConnectionFactory
[javac] private static ServiceRecord srWAP2[];
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:80: cannot find symbol
[javac] symbol : class HttpHeaders
[javac] location: class HttpConnectionFactory
[javac] public HttpConnection getHttpConnection(String pURL, HttpHeaders headers) {
[javac] ^
[javac] D:\sakina\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:88: cannot find symbol
[javac] symbol : class HttpHeaders
[javac] location: class HttpConnectionFactory
[javac] public HttpConnection getHttpConnection(String pURL, HttpHeaders headers, byte[] data) {
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:123: cannot find symbol
[javac] symbol : class HttpHeaders
[javac] location: class HttpConnectionFactory
[javac] private HttpConnection tryHttpConnection(String pURL, int tIndex, HttpHeaders headers, byte[] data) {
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:61: cannot find symbol
[javac] symbol : variable DeviceInfo
[javac] location: class HttpConnectionFactory
[javac] sb.append(DeviceInfo.getDeviceName());
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:69: cannot find symbol
[javac] symbol : variable Branding
[javac] location: class HttpConnectionFactory
[javac] sb.append(Branding.getVendorId());
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:206: cannot find symbol
[javac] symbol : variable HttpProtocolConstants
[javac] location: class HttpConnectionFactory
[javac] con.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, HttpProtocolConstants.CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED);
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:206: cannot find symbol
[javac] symbol : variable HttpProtocolConstants
[javac] location: class HttpConnectionFactory
[javac] con.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, HttpProtocolConstants.CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED);
[javac] ^
[javac] D:\bol
[javac] symbol : variable HttpProtocolConstants
[javac] location: class HttpConnectionFactory
[javac] con.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, String.valueOf(data.length));
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:236: cannot find symbol
[javac] symbol : variable DeviceInfo
[javac] location: class HttpConnectionFactory
[javac] if (DeviceInfo.isSimulator()) {
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:248: cannot find symbol
[javac] symbol : variable CoverageInfo
[javac] location: class HttpConnectionFactory
[javac] if (CoverageInfo.isCoverageSufficient(4 /* CoverageInfo.COVERAGE_BIS_B */)) {
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:255: cannot find symbol
[javac] symbol : variable CoverageInfo
[javac] location: class HttpConnectionFactory
[javac] if (CoverageInfo.isCoverageSufficient(2 /* CoverageInfo.COVERAGE_MDS */)) {
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:262: cannot find symbol
[javac] symbol : variable WLANInfo
[javac] location: class HttpConnectionFactory
[javac] if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
[javac] ^
[javac] D:\sakina\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:262: cannot find symbol
[javac] symbol : variable WLANInfo
[javac] location: class HttpConnectionFactory
[javac] if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:271: cannot find symbol
[javac] symbol : variable CoverageInfo
[javac] location: class HttpConnectionFactory
[javac] if (CoverageInfo.isCoverageSufficient(1 /* CoverageInfo.COVERAGE_DIRECT */) && (srWAP2 != null) && (srWAP2.length != 0)) {
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:278: cannot find symbol
[javac] symbol : variable CoverageInfo
[javac] location: class HttpConnectionFactory
[javac] if (CoverageInfo.isCoverageSufficient(1 /* CoverageInfo.COVERAGE_DIRECT */)) {
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:305: cannot find symbol
[javac] symbol : class ServiceBook
[javac] location: class HttpConnectionFactory
[javac] ServiceBook sb = ServiceBook.getSB();
[javac] ^
[javac] D:\sTTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:305: cannot find symbol
[javac] symbol : variable ServiceBook
[javac] location: class HttpConnectionFactory
[javac] ServiceBook sb = ServiceBook.getSB();
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:306: cannot find symbol
[javac] symbol : class ServiceRecord
[javac] location: class HttpConnectionFactory
[javac] ServiceRecord[] records = sb.getRecords();
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:314: cannot find symbol
[javac] symbol : class ServiceRecord
[javac] location: class HttpConnectionFactory
[javac] ServiceRecord myRecord = records[i];
[javac] ^
[javac] D:\TTMF_ProjectUAT1\TTMFBlackBerry\src\HttpConnectionFactory.java:326: cannot find symbol
[javac] symbol : class ServiceRecord
[javac] location: class HttpConnectionFactory
[javac] srWAP2 = new ServiceRecord[wap2Vec.size()];
[javac] ^
[javac] 29 errors
[javac] If an API-class was not found, you might need to define where to find the device-APIs. Following classpath has been used: [C:\Program Files\J2ME-Polish\import\mmapi.jar;C:\Program Files\J2ME-Polish\import\cldc-1.1.jar;C:\Program Files\J2ME-Polish\import\midp-2.0.jar;C:/Program Files/J2ME-Polish/import/jsr238.jar;C:/Program Files/J2ME-Polish/import/jsr234.jar;C:/Program Files/J2ME-Polish/import/jsr211.jar;C:/Program Files/J2ME-Polish/import/jsr180.jar;C:/Program Files/J2ME-Polish/import/locationapi-1.0.jar;C:/Program Files/J2ME-Polish/import/jsr177.jar;C:/Program Files/J2ME-Polish/import/jsr172.jar;C:/Program Files/J2ME-Polish/import/pdaapi.jar;C:/Program Files/J2ME-Polish/import/btapi.jar;C:/Program Files/J2ME-Polish/import/m3g.jar;C:/Program Files/J2ME-Polish/import/wmapi-2.0.jar;C:/Program Files/J2ME-Polish/import/m2g.jar].
建立失败
尽管添加了BlackBerry-5.0.0.jar文件
答案 0 :(得分:0)
这是获得可用连接和顺利运行项目的最佳方式
在以下链接中我指定了两个类
1)HttpConnectionFactory 2)HttpConnectionFactoryException
click here to see the above classes
将这两个类复制到您的项目中
编写以下代码(已在链接中指定) 这将按照某种顺序检查所有可用的连接 1)WIFI 2)双 3)BES 4)TCP 5)WAP 这是第一次可用,然后它将停止检查并采取该连接来运行项目
HttpConnectionFactory factory = new HttpConnectionFactory(0);
Httpconnection httpConnection = factory.getHttpConnection(url);
if(httpConnection.getResponseCode()==HttpConnection.HTTP_OK){
//some of the connection in available
}else{
//no connection available
}
如果我错了,请忽略此
答案 1 :(得分:0)
如果这是Link并采用 HttpConnection.java 并尝试一下。如果它不起作用,请在同一链接上看到“peter_strange”帖子。在那里,他提供了可以帮助您的链接;