开发者

Blackberry app is not fetching data through internet on device

I am working on an application which is fetching data from the server and parsing the xml and showing it in the list view. But the problem is that the code is running fine on the simulator but when i install the app on device its not fetching the data from server( Not connecting to internet ).

I have signed the app with BB keys so no error on that part.

Here is some of my code .. I am using to connect to internet -

public XMLParser() throws SAXException, IOException{

             // connect to feed's URL
            String url=urlToHit;
            System.out.println(url);
            try {
                httpConnection = (HttpConnection)Connector.open(url);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            try {
                inputStream = httpConnection.openDataInputStream();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if(httpConnection.getResponseCode() == HttpConnection.HTTP_OK)
            {
                // check header field for a specific encoding
                String desiredEncoding = "ISO-8859-1";  //iso-8859-1
                String contenttype = httpConnection.getHeaderField("Content-Type");
                if (contenttype != null)
                {
                    contenttype = contenttype.toUpperCase();
                    if (contenttype.indexOf("UTF-8") != -1)
                    {
                        desiredEncoding = "UTF-8";
                    }
                }

                // we need an input source for the sax parser
                InputSource is = new InputSource(inputStream);

                // setup Encoding to match what the web server sent us
                is.setEncoding(desiredEncoding);

                // create the factory
                SAXParserFactory factory = SAXParserFactory.newInstance();

                // create a parser
                SAXParser parser = null;
                try {
                    parser = factory.newSAXParser();
                } catch (ParserConfigurationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SAXException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                // instantiate our handler
                DefaultHandler myHandler= new DefaultHandler(){


                    public void startElement(String uri, String localName,String element_name, Attributes attributes)throws SAXException{


                        if (element_name.equals("Books")){
                            bookCount=attributes.getValue("booksCount");

                    }
                    if (element_name.equals("Book")){

                        TableRowManager row = new TableRowManager();

                        Bitmap scaledBitmap = new Bitmap(50, 70);

                        Bitmap img=Bitmap.createBitmapFromBytes((getImageFromUrl(attributes.getValue("image")).getBytes()), 0,-1, 1);

                        img.scaleInto(scaledBitmap,  Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FIT);
                        //img=(new WebBitmapField(attributes.getValue("image"))).getBitmap();
                        row.add(new BitmapField(scaledBitmap));

                        row.add(new LabelField(attributes.getValue("title"),DrawStyle.ELLIPSIS));
                        //row.add(new BitmapField(attributes.getValue("image"),));
                        LabelField lf1=new LabelField("Author:"+attributes.getValue("author"),DrawStyle.ELLIPSIS){

                            protected void paint(Graphics graphics) {
                             graphics.setColor(0x00878787);

                             super.paint(graphics);

                           }
                        };

                        row.add(lf1);
                        LabelField lf2=new LabelField("ISBN:"+attributes.getValue("isbn13"),DrawStyle.ELLIPSIS){

                            protected void paint(Graphics graphics) {
                             graphics.setColor(0x00878787);

                             super.paint(graphics);

                           }
                        };

                        row.add(lf2);

                        LabelField lf3=new LabelField("year:"+attributes.getValue("year"),DrawStyle.ELLIPSIS){

                     开发者_开发百科       protected void paint(Graphics graphics) {
                             graphics.setColor(0x00878787);

                             super.paint(graphics);

                           }
                        };

                        row.add(lf3);

                        title.addElement(attributes.getValue("title"));
                        isbn.addElement(attributes.getValue("isbn13"));
                        bookImg.addElement(attributes.getValue("image"));
                        author.addElement(attributes.getValue("author"));
                        year.addElement(attributes.getValue("year"));



                        row.add(new BitmapField(p1));

                        rows.addElement(row);
                    }

                    }
                    public void characters(char[] ch, int start, int len) throws SAXException{



                    }

                };

                // perform the synchronous parse           
                parser.parse(is,myHandler);
            }



        }

Please suggest.


Appending the URL with ;deviceside=true means you are using the DIRECT_TCP transport. On some wireless providers this transport also requires APN settings to be configured on device. Note the APN settings are usually wireless provider specific.

Googling you can find APN settings for your wireless provider. For instance, check this link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜