Your HttpConnection code is independent from the type of data
connectivity (whether it's wifi or cellular).
There are no changes needed on your code.

Changes might be needed when the requirements for data connectivity on
Wifi are different than on cellular data. For example it might be that
you are on Wifi behind a firewall and that you have to talk to a proxy
to be able to connect to the internet. In this case you want to make
sure that you correctly  get data connectivity setup in the Wifi
environment you are working in. Your main application code does not
change.


--
Roman Baumgaertner
Sr. SW Engineer-OSDC
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.


On Oct 28, 11:25 pm, Nemat <[email protected]> wrote:
> Hi Friends....
>
> I have written my HttpConnection code for Android.I have also set
> Network preferences. Should I change the code so that it would be able
> to work for Wifi?or I dont need any change.Does the same code work for
> Wifi correctly?Here is my code:
>
> public static String http_get(String urlParameters)
>           {
>                     String msg = "",uid = "";
>                     int ch;
>
>                     url = url + urlParameters ;
>
>                     int BUFFER_SIZE = 2000;
>                     InputStream in = null;
>                     try {
>                         in = OpenHttpConnection(url);
>                     } catch (IOException e1) {
>                         // TODO Auto-generated catch block
>                         e1.printStackTrace();
>
>                     }
>
>                     try
>                     {
>                          InputStreamReader isr = new InputStreamReader
> (in);
>                          int charRead;
>                            String str = "";
>                            char[] inputBuffer = new char
> [BUFFER_SIZE];
>                          try {
>                              while ((charRead = isr.read(inputBuffer))>0)
>
>                              {
>                                  //---convert the chars to a String---
>                                  String readString =
>                                      String.copyValueOf(inputBuffer,
> 0, charRead);
>                                  str += readString;
>                                  inputBuffer = new char[BUFFER_SIZE];
>                              }
>                              in.close();
>                          } catch (IOException e) {
>                              // TODO Auto-generated catch block
>                              e.printStackTrace();
>
>                          }
>                          Log.i("Server",str);
>
>                               if(str.indexOf("1_")!=-1)
>                               {
>
>                                     uid = str.substring(2);
>
>                               }
>                               else
>                               {
>
>                                  uid="0";
>
>                               }
>
>                     }
>                     catch (Exception e)
>                     {
>                               msg = e.toString();
>                     }
>                     return uid;
>           }
>
>   public static String postData(String user,String file, String
> Contents){
>
>               // Create a new HttpClient and Post Header
>               HttpClient httpclient = new DefaultHttpClient();
>               HttpPost httppost = new HttpPost(url+file);
>               String result="";
>
>           try {
>                // Add your data
>                List<NameValuePair> nameValuePairs = new
> ArrayList<NameValuePair>(1);
>                Log.i("POSTDATA",user);
>                nameValuePairs.add(new BasicNameValuePair("sID",
> user));
>                nameValuePairs.add(new BasicNameValuePair("content",
> Contents));
>                httppost.setEntity(new UrlEncodedFormEntity
> (nameValuePairs));
>
>                // Execute HTTP Post Request
>                HttpResponse response = httpclient.execute(httppost);
>
>                InputStream is = response.getEntity().getContent();
>                BufferedInputStream bis = new BufferedInputStream(is);
>                ByteArrayBuffer baf = new ByteArrayBuffer(20);
>
>                 int current = 0;
>                 while((current = bis.read()) != -1){
>                     baf.append((byte)current);
>                 }
>                   Log.d("GETANDPOST",new String(baf.toByteArray()));
>                   result=new String(baf.toByteArray());
>                /* Convert the Bytes read to a String. */
>           //     text = new String(baf.toByteArray());
>              //  tv.setText(text);
>
>           } catch (ClientProtocolException e) {
>                // TODO Auto-generated catch block
>           } catch (IOException e) {
>                // TODO Auto-generated catch block
>           }
>           return result;
>      }
>
> public String SetPreference() {
>         ConnectivityManager
> connMgr=(ConnectivityManager)getSystemService
> (this.CONNECTIVITY_SERVICE);
>         NetworkInfo info=connMgr.getActiveNetworkInfo();
>         connMgr.setNetworkPreference(ConnectivityManager.TYPE_WIFI);
>                    return (connMgr.getActiveNetworkInfo().getTypeName
> ());
>
> }
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to