Posted By

arunmishra07 on 05/06/11


Tagged

internet android


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Bondergaard


Internet Connection in Android


 / Published in: Java
 

  1. private void callToWebSrvice() {
  2.  
  3. ConnectivityManager connManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
  4.  
  5. if (connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || connManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED ) {
  6. _progresssDialog = ProgressDialog.show(this,"Please Wait...","Retrieving Data");
  7. getData();
  8. } else
  9. Toast.makeText(BestScore.this, "Network Error!!!", Toast.LENGTH_LONG).show();
  10.  
  11. }
  12. public void getData(){
  13.  
  14. Thread _thread = new Thread(){
  15.  
  16. public void run(){
  17.  
  18. Message _msg = new Message();
  19. _msg.what = _updataSmsLog;
  20. callDataBase();
  21. BestScore.this._uicallback.sendMessage(_msg);
  22. }
  23. };
  24. _thread.start();
  25. }
  26.  
  27. Handler _uicallback = new Handler(){
  28.  
  29. public void handleMessage(Message msg) {
  30.  
  31.  
  32. switch(msg.what){
  33.  
  34. case _updataSmsLog :
  35.  
  36. if(_dataList.size() > 0 ){
  37.  
  38.  
  39. _initial.setText(((Data)(_dataList.get(0)))._initial);
  40. _wpm.setText(((Data)(_dataList.get(0)))._wpm);
  41. _phone.setText(((Data)(_dataList.get(0)))._smartPhone);
  42. _country.setText(((Data)(_dataList.get(0)))._country);
  43.  
  44. _progresssDialog.dismiss();
  45. setListAdapter(new IconicAdator(BestScore.this,R.layout.viewrow,_dataList));
  46. }
  47. else{
  48.  
  49. _progresssDialog.dismiss();
  50. Toast.makeText(BestScore.this,"No Record Found",Toast.LENGTH_LONG).show();
  51. }
  52. }
  53.  
  54. };
  55.  
  56. };

Report this snippet  

You need to login to post a comment.