Question

I have created Blackberry Application which is working perfectly fine on wi-fi. But when I turn off wi-fi and use Mobile Network then I am not able to run application. It shows No Internet connection available.

I had written these lines.

if (DeviceInfo.isSimulator()) 
            {
                deviceinfo = deviceinfo.concat(";deviceside=true");
            }

Here is My Http Connection Class

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;
//  }



}
Was it helpful?

Solution

Actually solution is found.

java.io.IOException:APN is not specified . what APN i have to set manually to device for Wi-Fi network?

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

Refer this link.

Actually we have to set APN manually. We get it from the Provider.

I hope someone get solution from my this answer. Thanks a lot for your support.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top