是否有任何RIM API可用于获取设备的可用网络服务列表或仅获取Wi-Fi网络,并为任何网络通信设置选定的网络接入点?
我的应用程序是否可以禁用GPRS,WAP等移动网络?
例:
启动应用程序后,即使设备上没有设置先前的Wi-Fi网络接入点,也应扫描Wi-Fi连接,并列出可用的Wi-Fi连接。然后,用户将选择适当的Wi-Fi连接以进行任何网络通信。在应用程序之外,任何Internet通信(如浏览器或任何其他应用程序)都应通过相同的选定Wi-Fi连接完成。
扫描Wi-Fi并设置连接几乎与BlackBerry Wi-Fi Setup相似。
我希望为BlackBerry OS 4.5,4.7和5.0执行此操作。
更新
我正在寻找通过应用程序进行Wi-Fi扫描的事情。就像通过应用程序一样,我能够扫描可用的Wi-Fi接入点或热点,并通过选择一个接入点来设置它,然后连接到它进行通信。
基本上就是这样,我们如何在BlackBerry的“管理连接”中设置Wi-Fi连接?我必须通过应用程序做类似的事情。
从一些黑莓论坛我发现OS v5.0中有一个包,就是一个 net.rim.device.api.wlan.hotspot 包来获取Wi-Fi热点。但经过长时间的搜索,我没有找到任何示例或解释。正如我试图通过查看其API文档来实现,但我没有成功。
如果您对此或任何示例代码有任何想法,那将非常有用。
答案 0 :(得分:5)
那么,要扫描应用程序的所有可用网络,您可以使用RIM中的NetworkDiagnostic tool。
可以在 How to reliably establish a network connection on any BlackBerry device 中找到用于扫描手机连接并获取最佳连接字符串的另一段代码,
/**
* Determines what connection type to use and returns the necessary string to use it.
* @return A string with the connection info
*/
private static String getConnectionString()
{
// This code is based on the connection code developed by Mike Nelson of AccelGolf.
// http://blog.accelgolf.com/2009/05/22/blackberry-cross-carrier-and-cross-network-http-connection
String connectionString = null;
// Simulator behavior is controlled by the USE_MDS_IN_SIMULATOR variable.
if (DeviceInfo.isSimulator())
{
if (UploaderThread.USE_MDS_IN_SIMULATOR)
{
logMessage("Device is a simulator and USE_MDS_IN_SIMULATOR is true");
connectionString = ";deviceside=false";
}
else
{
logMessage("Device is a simulator and USE_MDS_IN_SIMULATOR is false");
connectionString = ";deviceside=true";
}
}
// Wi-Fi is the preferred transmission method.
else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
{
logMessage("Device is connected via Wifi.");
connectionString = ";interface=wifi";
}
// Is the carrier network the only way to connect?
else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT)
{
logMessage("Carrier coverage.");
String carrierUid = getCarrierBIBSUid();
if (carrierUid == null)
{
// Has carrier coverage, but not BIBS. So use the carrier's TCP network
logMessage("No Uid");
connectionString = ";deviceside=true";
}
else
{
// otherwise, use the Uid to construct a valid carrier BIBS request
logMessage("uid is: " + carrierUid);
connectionString = ";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)
{
logMessage("MDS coverage found");
connectionString = ";deviceside=false";
}
// If there is no connection available abort to avoid bugging the user unnecssarily.
else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
{
logMessage("There is no available connection.");
}
// In theory, all bases are covered so this shouldn't be reachable.
else
{
logMessage("no other options found, assuming device.");
connectionString = ";deviceside=true";
}
return connectionString;
}
/**
* Looks through the phone's service book for a carrier provided BIBS network
* @return The uid used to connect to that network.
*/
private 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;
}