我创建了Blackberry Application,它在Wi-Fi上运行得非常好。但是当我关闭Wi-Fi并使用移动网络时,我无法运行应用程序。它显示没有可用的Internet连接。
我写过这些文字。
if (DeviceInfo.isSimulator())
{
deviceinfo = deviceinfo.concat(";deviceside=true");
}
这是我的Http连接类
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.system.DeviceInfo;
import net.rim.device.api.system.RadioInfo;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
public class HttpConn
{
public String jsonresponse (String url)
{
String response = null;
HttpConnection httpConnection = null;
InputStream inStream = null;
int code;
StringBuffer stringBuffer = new StringBuffer();
String deviceinfo=url;
try
{
if (DeviceInfo.isSimulator())
{
deviceinfo = deviceinfo.concat(";deviceside=true");
}
/* else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
{
deviceinfo = ";interface=wifi";
}*/
else if ( (RadioInfo.getActiveWAFs() & RadioInfo.WAF_WLAN) != 0 && RadioInfo.getSignalLevel( RadioInfo.WAF_WLAN ) != RadioInfo.LEVEL_NO_COVERAGE )
{
deviceinfo = deviceinfo.concat(";interface=wifi");
}
// else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
// {
// deviceinfo = ";interface=wifi";//
// }
if ( (RadioInfo.getActiveWAFs() & RadioInfo.WAF_WLAN) != 0 && RadioInfo.getSignalLevel( RadioInfo.WAF_WLAN ) != RadioInfo.LEVEL_NO_COVERAGE )
{
deviceinfo = deviceinfo.concat(";interface=wifi");
}
// else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT)
// {
// String carrierUid = getCarrierBIBSUid();
//
// if (carrierUid == null)
// {
// // Has carrier coverage, but not BIBS. So use the carrier's TCP
// // network
//
// deviceinfo = ";deviceside=true";
//
// }
// else
// {
// // otherwise, use the Uid to construct a valid carrier BIBS
// // request
//
// deviceinfo = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=mds-public";
//
// }
// }
//
// // Check for an MDS connection instead (BlackBerry Enterprise Server)
// else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS)
// {
//
// deviceinfo = ";deviceside=false";
//
// }
//
// // If there is no connection available abort to avoid hassling the user
// // unnecssarily.
// else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
// {
// deviceinfo = "none";
//
//
// }
// else
// {
// deviceinfo=";deviceside=true";
// }
//if(CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_DIRECT,RadioInfo.WAF_WLAN,false))
// httpConnection = (HttpConnection) Connector.open(url+";interface=wifi", Connector.READ);
httpConnection = (HttpConnection) Connector.open(deviceinfo, Connector.READ);
httpConnection.setRequestMethod(HttpConnection.GET);
code = httpConnection.getResponseCode();
if(code == HttpConnection.HTTP_OK)
{
inStream=httpConnection.openInputStream();
int c;
while((c=inStream.read())!=-1)
{
stringBuffer.append((char)c);
}
response=stringBuffer.toString();
System.out.println("Response Getting from Server is ================" + response);
}
// Is the carrier network the only way to connect?
// In theory, all bases are covered by now so this shouldn't be reachable.But hey, just in case ...
else
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.inform("Connection error");
}
});
}
// return deviceinfo;
}
catch (Exception e)
{
System.out.println("caught exception in jsonResponse method"+e.getMessage());
}
finally
{
// if (outputStream != null)
// {
// outputStream.close();
// }
if (inStream != null)
{
try
{
inStream.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (httpConnection != null )
{
try
{
httpConnection.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return response;
}
// private synchronized static String getCarrierBIBSUid() {
// ServiceRecord[] records = ServiceBook.getSB().getRecords();
// int currentRecord;
//
// for (currentRecord = 0; currentRecord < records.length; currentRecord++) {
// if (records[currentRecord].getCid().toLowerCase().equals("ippp")) {
// if (records[currentRecord].getName().toLowerCase()
// .indexOf("bibs") >= 0) {
// return records[currentRecord].getUid();
// }
// }
// }
//
// return null;
// }
}
答案 0 :(得分:1)
实际上找到了解决方案。
http://m2m.icpdas.com/download/gtm-201_modem/manual/gprs_apn.pdf
http://www.faqspedia.com/list-of-all-indian-mobile-operators-access-point-names
请参阅此链接。
实际上我们必须手动设置APN。我们从提供商那里得到它。
我希望有人从我的答案中得到解决方案。非常感谢您的支持。