Je sais que ce fil est fermé depuis longtemps, mais pensé laisser tomber cette Incase quelqu'un a besoin là-bas un jour. Ce problème a vraiment ralenti mon développement pendant des heures et j'ai donc jugé bon de le partager. Je vais fournir deux méthodes qui aideront à vérifier l'appareil et utiliser le transport approprié disponible. Pour utiliser cette méthode, appelez simplement la méthode getConnectionString et ajoutez-la à la fin de votre chaîne d'URL et vous êtes prêt à partir.
//the method returns the connection string
public String getConnectionString()
{
String connectionString = "";
if(DeviceInfo.isSimulator())
{
if(true)// toggle between true and false to enable simulator use mds
{
// Log.i(TAG, "Device is a simulator and USE_MDS_IN_SIMULATOR is true");
connectionString = ";deviceside=false";
}
else
{
// Log.i(TAG, "Device is a simulator and USE_MDS_IN_SIMULATOR is false");
connectionString = ";deviceside=true";
}
}
// Wifi is the preferred transmission method
else if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
{
// Log.i(TAG, "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)
{
// Log.i(TAG, "Carrier coverage.");
String carrierUid = getCarrierBIBSUid();
if(carrierUid == null)
{
// Has carrier coverage, but not BIBS. So use the carrier's TCP network
// Log.i(TAG, "No Uid");
connectionString = ";deviceside=true";
}
else
{
// otherwise, use the Uid to construct a valid carrier BIBS request
// Log.i(TAG, "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)
{
// Log.i(TAG, "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)
{
// Log.i(TAG, "There is no available connection.");
}
// In theory, all bases are covered so this shouldn't be reachable.
else
{
// Log.i(TAG, "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. This is called from getConnectionString()
*/
private 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;
}
Exemple d'utilisation se trouve ci-dessous:
String url = "specific url"+getConnectionString();
HttpConnection connection = (HttpConnection)Connector.open(url, Connector.READ, true);
Cette méthode est la preuve complète et a été testé sur plusieurs appareils, donc je pensais que de le mettre dans un format concis ici. Bonne chance
en utilisant api non signé résout dans le message d'erreur, donc probablement ses autorisations de connexion ou d'application. quel genre de connexion utilisez-vous? utilisez-vous BES? –