Poderiam me enviar um código para conecção http que tenha funcionado bem com diversas marcas e modelos de aparelhos celulares, o código que utilizo não está funcionando com modelos de aparelhos celulares da marca Motorola.
Funcionou nos emuladores da sonyEricsson e Motorola que eu testei aqui.
importjava.io.*;importjavax.microedition.io.*;importjavax.microedition.lcdui.*;importjavax.microedition.midlet.*;publicclassImageLoaderextendsMIDletimplementsCommandListener,Runnable{privateDisplaymDisplay;privateFormmForm;publicImageLoader(){mForm=newForm("Connecting...");mForm.addCommand(newCommand("Exit",Command.EXIT,0));mForm.setCommandListener(this);}publicvoidstartApp(){if(mDisplay==null)mDisplay=Display.getDisplay(this);mDisplay.setCurrent(mForm);// Do network loading in a separate thread. Threadt=newThread(this);t.start();}publicvoidpauseApp(){}publicvoiddestroyApp(booleanunconditional){}publicvoidcommandAction(Commandc,Displayables){if(c.getCommandType()==Command.EXIT)notifyDestroyed();}publicvoidrun(){HttpConnectionhc=null;DataInputStreamin=null;try{hc=(HttpConnection)Connector.open("http://www.portaljava.com/home/images/topics/java.gif");intlength=(int)hc.getLength();byte[]data=null;if(length!=-1){data=newbyte[length];in=newDataInputStream(hc.openInputStream());in.readFully(data);}else{// If content length is not given, read in chunks.intchunkSize=512;intindex=0;intreadLength=0;in=newDataInputStream(hc.openInputStream());data=newbyte[chunkSize];do{if(data.length<index+chunkSize){byte[]newData=newbyte[index+chunkSize];System.arraycopy(data,0,newData,0,data.length);data=newData;}readLength=in.read(data,index,chunkSize);index+=readLength;}while(readLength==chunkSize);length=index;}Imageimage=Image.createImage(data,0,length);ImageItemimageItem=newImageItem(null,image,0,null);mForm.append(imageItem);mForm.setTitle("Done.");}catch(IOExceptionioe){StringItemstringItem=newStringItem(null,ioe.toString());mForm.append(stringItem);mForm.setTitle("Done.");}finally{try{if(in!=null)in.close();if(hc!=null)hc.close();}catch(IOExceptionioe){}}}}
L
luizaisPJ
Realmente o código citado funciona no emulador motorola, porém no aparelho Motorola V3 fornece o mesmo erro que estava tendo. Será que é necessário de efetuar alguma configuração especial no aparelho?