服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - android网络编程之android连接网络的简单示例代码

android网络编程之android连接网络的简单示例代码

2021-02-28 14:03Android开发网 Android

这篇文章主要介绍了android连接网络的简单示例,需要的朋友可以参考下

复制代码 代码如下:

private void callToWebSrvice() {

    ConnectivityManager connManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

    if (connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||  connManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED  ) {
       _progresssDialog = ProgressDialog.show(this,"Please Wait...","Retrieving Data");
       getData(); 
    } else
        Toast.makeText(BestScore.this, "Network Error!!!", Toast.LENGTH_LONG).show();          

}
public void getData(){

    Thread _thread = new Thread(){

        public void run(){

            Message _msg = new Message();
            _msg.what = _updataSmsLog;
            callDataBase();
            BestScore.this._uicallback.sendMessage(_msg);
        }
    };
    _thread.start();
}

Handler _uicallback = new Handler(){

    public void handleMessage(Message msg) {

        switch(msg.what){

            case _updataSmsLog :

                if(_dataList.size() > 0 ){

                        _initial.setText(((Data)(_dataList.get(0)))._initial);
                        _wpm.setText(((Data)(_dataList.get(0)))._wpm);
                        _phone.setText(((Data)(_dataList.get(0)))._smartPhone);
                        _country.setText(((Data)(_dataList.get(0)))._country);

                    _progresssDialog.dismiss();
                    setListAdapter(new IconicAdator(BestScore.this,R.layout.viewrow,_dataList));
                }
                else{

                    _progresssDialog.dismiss();
                    Toast.makeText(BestScore.this,"No Record Found",Toast.LENGTH_LONG).show();
                }
        }

    };

};

延伸 · 阅读

精彩推荐