我已经完成了一个android应用程序,从位于web服务器上的数据库读取(php,json,.)。如果服务器关闭或未找到ip地址,应用程序将显示:
不幸的是,应用程序已经停止。
我想显示自定义错误信息,而不是。例如,“无法到达服务器”,应用程序继续正常工作。
如何检查可访问或可用的服务器或ip地址以避免预览消息?
发布于 2013-07-03 08:49:49
此代码解决了问题:
public static boolean ping()
{
System.out.println(" executeCammand");
Runtime runtime = Runtime.getRuntime();
try
{
Process mIpAddrProcess = runtime.exec("/system/bin/ping -c 1 "+server);
int mExitValue = mIpAddrProcess.waitFor();
if(mExitValue==0){
return true;
}else{
return false;
}
}
catch (InterruptedException ignore)
{
}
catch (IOException e)
{
}
return false;
}https://stackoverflow.com/questions/17420015
复制相似问题