Android检查互联网连接我想要创建一个使用互联网的应用程序,我正在尝试创建一个函数来检查连接是否可用,如果没有,请转到一个有重试按钮和说明的活动。到目前为止,附加的代码是我的代码,但是我得到了错误Syntax error, insert "}" to complete MethodBody.我一直在努力让它发挥作用,但到目前为止没有运气.任何帮助都将不胜感激。public class TheEvoStikLeagueActivity extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 3000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
private boolean checkInternetConnection() {
ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
// ARE WE CONNECTED TO THE NET
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {
return true;
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable() {
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(TheEvoStikLeagueActivity.this, IntroActivity.class);
TheEvoStikLeagueActivity.this.startActivity(mainIntent);
TheEvoStikLeagueActivity.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
} else {
return false;
Intent connectionIntent = new Intent(TheEvoStikLeagueActivity.this, HomeActivity.class);
TheEvoStikLeagueActivity.this.startActivity(connectionIntent);
TheEvoStikLeagueActivity.this.finish();
}
}
}
3 回答
- 3 回答
- 0 关注
- 456 浏览
添加回答
举报
0/150
提交
取消