2014-04-11 2 views
0

내가 할 필요가 내 응용 프로그램 중 하나에있는 모든 안녕하세요 ... 내가이안드로이드 핑

public class UrlPinger extends AsyncTask<URL, Void, Void> { 

     @Override 
     protected Void doInBackground(URL... urls) { 
      URL url = urls[0]; 

      try { 
       HttpURLConnection urlConnection = (HttpURLConnection) url 
         .openConnection(); 
       urlConnection.connect(); 
       System.out.println("thisi si wie URL>>>"+url+""); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
       System.out.println("ERROR "+e.getMessage()+""); 
      } 

      return null; 

     } 

위의 클래스 나에게 오류를 포기하지 않을 수행 한 모든 URL을 명중 URL을 잘못 누르지 않았습니까? 이

UrlPinger pinger = new UrlPinger(); 
        pinger.execute(myURL);// this is perfect url copy pase in browser hits 

처럼 호출은 <uses-permission android:name="android.permission.INTERNET"></uses-permission> 내 로그 캣 준 :

04-11 11:32:09.206: D/StatusBar.NetworkController(1154): refreshViews: Data not connected!! Set no data type icon 
04-11 11:32:09.206: D/StatusBar.NetworkController(1154): refreshViews connected={ wifi } level=4 combinedSignalIconId=0x7f0200c1/com.android.systemui:drawable/stat_sys_wifi_signal_4_fully combinedActivityIconId=0x7f0200b1 mobileLabel=BSNL MOBILE wifiLabel=LeewayxxxxXXXXxxxxXXXX emergencyOnly=false combinedLabel=LeewayxxxxXXXXxxxxXXXX mAirplaneMode=false mDataActivity=0 mPhoneSignalIconId=0x7f0200a7 mDataDirectionIconId=0x0 mDataSignalIconId=0x7f0200a7 mDataTypeIconId=0x0 mNoSimIconId=0x0 mWifiIconId=0x7f0200c1 mBluetoothTetherIconId=0x108076a 
04-11 11:32:09.206: D/StatusBar.NetworkController(1154): changing data overlay icon id to 2130837681 
04-11 11:32:10.657: D/StateMachine(651): handleMessage: E msg.what=131155 
04-11 11:32:10.657: D/StateMachine(651): processMsg: ConnectedState 
04-11 11:32:10.657: D/WifiStateMachine(651): ConnectedState{ what=131155 when=-6ms arg1=1121 } 
04-11 11:32:10.657: D/StateMachine(651): processMsg: L2ConnectedState 
04-11 11:32:10.657: D/WifiStateMachine(651): L2ConnectedState{ what=131155 when=-9ms arg1=1121 } 
04-11 11:32:10.657: I/wpa_supplicant(17672): wlan0: Control interface command 'SIGNAL_POLL' 
04-11 11:32:10.667: D/StateMachine(651): handleMessage: X 
04-11 11:32:11.208: W/SignalStrength(1154): getLTELevel - rsrp:2147483647 snr:2147483647 rsrpIconLevel:-1 snrIconLevel:-1 
04-11 11:32:11.208: W/SignalStrength(1154): getLTELevel - rssi:99 rssiIconLevel:0 
04-11 11:32:11.208: W/SignalStrength(1154): getTdScdmaLevel = 0 
04-11 11:32:11.208: W/SignalStrength(1154): getGsmLevel=4 
04-11 11:32:11.208: W/SignalStrength(1154): getLevel=4 
04-11 11:32:11.208: D/StatusBar.NetworkController(1154): refreshViews: Data not connected!! Set no data type icon 
04-11 11:32:11.208: D/StatusBar.NetworkController(1154): refreshViews connected={ wifi } level=4 combinedSignalIconId=0x7f0200c1/com.android.systemui:drawable/stat_sys_wifi_signal_4_fully combinedActivityIconId=0x0 mobileLabel=BSNL MOBILE wifiLabel=LeewayxxxxXXXXxxxxXXXX emergencyOnly=false combinedLabel=LeewayxxxxXXXXxxxxXXXX mAirplaneMode=false mDataActivity=0 mPhoneSignalIconId=0x7f0200a7 mDataDirectionIconId=0x0 mDataSignalIconId=0x7f0200a7 mDataTypeIconId=0x0 mNoSimIconId=0x0 mWifiIconId=0x7f0200c1 mBluetoothTetherIconId=0x108076a 
04-11 11:32:11.218: D/StatusBar.NetworkController(1154): changing data overlay icon id to 0 
04-11 11:32:13.681: D/StateMachine(651): handleMessage: E msg.what=131155 
04-11 11:32:13.681: D/StateMachine(651): processMsg: ConnectedState 
04-11 11:32:13.681: D/WifiStateMachine(651): ConnectedState{ what=131155 when=-3ms arg1=1121 } 
04-11 11:32:13.681: D/StateMachine(651): processMsg: L2ConnectedState 
04-11 11:32:13.681: D/WifiStateMachine(651): L2ConnectedState{ what=131155 when=-6ms arg1=1121 } 
04-11 11:32:13.681: I/wpa_supplicant(17672): wlan0: Control interface command 'SIGNAL_POLL' 
04-11 11:32:13.691: D/StateMachine(651): handleMessage: X 
04-11 11:32:16.694: D/StateMachine(651): handleMessage: E msg.what=131155 
04-11 11:32:16.694: D/StateMachine(651): processMsg: ConnectedState 
04-11 11:32:16.694: D/WifiStateMachine(651): ConnectedState{ what=131155 when=-5ms arg1=1121 } 
04-11 11:32:16.694: D/StateMachine(651): processMsg: L2ConnectedState 
04-11 11:32:16.694: D/WifiStateMachine(651): L2ConnectedState{ what=131155 when=-7ms arg1=1121 } 
04-11 11:32:16.694: I/wpa_supplicant(17672): wlan0: Control interface command 'SIGNAL_POLL' 
04-11 11:32:16.714: D/StateMachine(651): handleMessage: X 
04-11 11:32:19.707: D/StateMachine(651): handleMessage: E msg.what=131155 
04-11 11:32:19.707: D/StateMachine(651): processMsg: ConnectedState 
04-11 11:32:19.707: D/WifiStateMachine(651): ConnectedState{ what=131155 when=-4ms arg1=1121 } 
04-11 11:32:19.717: D/StateMachine(651): processMsg: L2ConnectedState 
04-11 11:32:19.717: D/WifiStateMachine(651): L2ConnectedState{ what=131155 when=-6ms arg1=1121 } 
04-11 11:32:19.717: I/wpa_supplicant(17672): wlan0: Control interface command 'SIGNAL_POLL' 
04-11 11:32:19.727: D/StateMachine(651): handleMessage: X 
04-11 11:32:22.730: D/StateMachine(651): handleMessage: E msg.what=131155 
04-11 11:32:22.730: D/StateMachine(651): processMsg: ConnectedState 
04-11 11:32:22.730: D/WifiStateMachine(651): ConnectedState{ what=131155 when=-5ms arg1=1121 } 
04-11 11:32:22.730: D/StateMachine(651): processMsg: L2ConnectedState 
04-11 11:32:22.740: D/WifiStateMachine(651): L2ConnectedState{ what=131155 when=-6ms arg1=1121 } 
04-11 11:32:22.740: I/wpa_supplicant(17672): wlan0: Control interface command 'SIGNAL_POLL' 
04-11 11:32:22.750: D/StateMachine(651): handleMessage: X 
+1

이 앱을 디버깅 할 당신의 로그 캣 정보 –

+0

을 확인을 ?? 오래 기다려야 할 것> – Sree

+0

try 블록에 예외가 발생하면 logcat 뷰에서 스택 추적을 확인하십시오. –

답변

0
HttpURLConnection connection = null; 
    try { 
     URL u = new URL("http://www.google.com/"); 
     connection = (HttpURLConnection) u.openConnection(); 
     connection.setRequestMethod("HEAD"); 
     int code = connection.getResponseCode(); 
     System.out.println("" + code); 
     // You can determine on HTTP return code received. 200 is success. 
    } catch (MalformedURLException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } finally { 
     if (connection != null) { 
      connection.disconnect(); 
     } 
    }