我有使用Internet的应用程序的工作。Android中的Internet连接
- 它包含URL的XML解析。 比
- 显示进度对话框在解析 时间。
- 解析完成时停止对话框。
- 在ListView中设置TEXT(数据)。
我的问题是,当设备连接到互联网比我的应用程序工作正常但是当设备没有连接到互联网“进度对话框”运行无限时间。
我想,如果设备没有连接到互联网或WiFi停止对话。这个怎么做?
有什么想法? 对不起家伙....我改变了主意,我想检查互联网连接,当我点击按钮。什么是截至目前为止我已经试过..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homelayout);
mclip = (ImageButton) findViewById(R.id.clip);
mclip.setClickable(true);
mclip.setFocusable(true);
mclip.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
//if it is connected to internet than start Another Activity.
startActivity(new Intent(ListViewExample.this, ClipOfDay.class));
} else if (netInfo == null) {
AlertDialog alertDialog = new AlertDialog.Builder(ListViewExample.this).create();
alertDialog.setTitle("Connection Problem");
alertDialog.setMessage("You are not connected to Internet");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
}
});
}
但这不是working.if设备没有连接到互联网,比我想显示AlertDialog。否则会启动Activity。任何人都可以告诉我该怎么办?
谢谢。
你是对的,但我怎么能检查是什么?我是新来的机器人,所以我不知道如何检查互联网连接。感谢您的回复。 – Piyush 2010-11-22 06:08:53
检查:HTTP://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-timeouts,尽量响应由埃迪·发送 – viv 2010-11-22 06:12:50