我想每秒调用以下代码部分?我尝试了以下方法-但不知道如何每秒调用一次?
我怎样才能继续调用 new checkNWConnectivity().execute("Test"); 每秒从哪里调用我的android程序???
private class checkNWConnectivity extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
ConnectivityManager manager = (ConnectivityManager)getSystemService(MainActivity.CONNECTIVITY_SERVICE);
// 3G confirm
Boolean is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
// wifi confirm
Boolean isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
if(is3g){
tvNWConnectivity.setText(" Connected to 3G");
}else if(isWifi){
tvNWConnectivity.setText(" Connected to wifi");
}else{
String text = " No Network Connectivity."+"\n" + " Uploading will be resumed from streamlet "+countStreamletUploaded.toString();
tvNWConnectivity.setText(text);
}
return null;
}
}
所以我的问题是如何每秒调用它? 实际上我想继续运行 doInBackground(String... params) { ... } 中的代码部分