我制作了一个脚本来检测是否有互联网连接:
public static boolean isOnline() {
try {
InetAddress.getByName("google.hu").isReachable(3);
return true;
} catch (UnknownHostException e){
return false;
} catch (IOException e){
return false;
}
}
如果没有互联网,该应用程序将警告用户并退出!但是如何将 super.onBackPressed 延迟 20 秒?:)
this.toast1 = new Toast(getApplicationContext());
toast1.setGravity(Gravity.CENTER, 0, 0);
toast1.setDuration(20000);
toast1.setView(layout);
toast1.show();
super.onBackPressed();