Andrid 打印调用堆栈
public static void printCallStatck() {
Throwable ex = new Throwable();
StackTraceElement[] stackElements = ex.getStackTrace();
if (stackElements != null) {
Log.e("Chw","printCallStatck+++++++++++++++++++++++");
for (int i = 0; i < stackElements.length; i++) {
Log.e("Chw",stackElements[i].getClassName()+"."+stackElements[i].getMethodName()+"-"+stackElements[i].getLineNumber());
}
Log.e("Chw","printCallStatck----end+++++++++++++++++++++++");
}
}
判断是否连接互联网
/**
* 判断是否有外网连接(普通方法不能判断外网的网络是否连接,比如连接上局域网)
* @return
*/
public static boolean ping(){
boolean result=false;
try {
String ip ="www.baidu.com";// ping 的地址,可以换成任何一种可靠的外网
Process process=Runtime.getRuntime().exec("ping -c 2 -w 100 "+ip);//ping 网址3次
int status= process.waitFor();
if(status==0){
result= true;
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.e("Chw","ping result "+result);
return result;
}
泰山崩于前而色不变的曹新雨,抱歉