2012-09-22 6 views
1

ceci est mon codeHttpConnection ne fonctionne pas dans le dispositif réel -Blackberry

public String Serverconnection(String url) { 

    String line = ""; 

    if (DeviceInfo.isSimulator()) { 
     url = url + ";deviceSide=true"; 
    } 
    try { 
     HttpConnection s = (HttpConnection) Connector.open(url);//*i get the exception here* 
     s.setRequestProperty("Content-Type", 
       "application/x-www-form-urlencoded"); 
     s.setRequestProperty(
       "Accept", 
       "text/html,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); 
     s.setRequestProperty(HttpHeaders.HEADER_ACCEPT_CHARSET, "UTF-8"); 
     s.setRequestMethod(HttpConnection.GET); 
     InputStream input = s.openInputStream(); 
     byte[] data = new byte[10240]; 
     int len = 0; 
     StringBuffer raw = new StringBuffer(); 

     while (-1 != (len = input.read(data))) { 
      raw.append(new String(data, 0, len)); 
     } 

     line = raw.toString(); 

     input.close(); 
     s.close(); 
    } catch (Exception e) { 
     System.out.println("response--- excep" + line + e.getMessage()); 
    } 
    return line; 

} 

ce code fonctionne bien quand je lance dans l'émulateur. Mais dans l'appareil réel, j'ai obtenu l'exception "détails indisponibles - non pris en charge par VM" "APN n'est pas spécifié."

Comment puis-je résoudre ce problème?

+0

vous devez ajouter le chaîne de connexion pour la connexion à Internet. – Signare

+0

vous connectez internet via wifi ou gprs? – Signare

+0

je me connecte à Internet via wifi – prakash

Répondre

4

se réfèrent à l'article du centre de connaissances "Different ways to make an HTTP or socket connection"

Append la chaîne de connexion à votre url.Then essayer

private static String getConnectionString(){ 
String connectionString=""; 
if(WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED){ 
    connectionString="?;interface=wifi"; 
} 

else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS){ 
    connectionString = "?;&deviceside=false"; 
} 
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT)==CoverageInfo.COVERAGE_DIRECT){ 
    String carrierUid=getCarrierBIBSUid(); 
    if(carrierUid == null) { 
     connectionString = "?;deviceside=true"; 
    } 
    else{ 
     connectionString = "?;deviceside=false?;connectionUID="+carrierUid + "?;ConnectionType=mds-public"; 
    }    
} 
else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) {   
     } 
    return connectionString; 
} 

Edit: -

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; 
} 
+0

salut Signare mai je sais "String carrierUid = getCarrierBIBSUid();" que fait cette méthode? – prakash

+0

J'ai mis à jour ma réponse. vérifiez la partie d'édition. – Signare

+0

génial ça marche ... – prakash

Questions connexes