Android中的互联网连接

【Android中的互联网连接】金鞍玉勒寻芳客,未信我庐别有春。这篇文章主要讲述Android中的互联网连接相关的知识,希望能为你提供帮助。

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


    推荐阅读