首页 > 系统 > Android > 正文

android连接网络的代码演示

2020-02-21 17:34:31
字体:
来源:转载
供稿:网友

手机是移动终端,它的计算能力和存储容量是有限的,因此网络支持对于移动应用也是非常重要的,那么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();
}
}

};

};

上文是android连接网络的代码演示,相信大家都有了一定的了解,想要了解更多的技术信息,请继续关注武林技术频道吧!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表