2013-05-03 115 views
0
  • 我正在實施Android(Java)。

我想在無法連接到服務器時拋出相應的錯誤消息。 (服務器關閉或沒有互聯網連接。)
似乎當沒有互聯網連接時,它返回一個帶有FacebookRequestError errorCode = -1 & requestCode = -1的響應。這是安全的,只想到沒有互聯網連接引發這個錯誤?換句話說,是否有其他錯誤拋出errorCode = -1 & requestCode = -1?Facebook的SDK:(請求)如何檢測無法連接到服務器或沒有互聯網連接

Request request = new Request(session, "me/friends", params, HttpMethod.GET, new Request.Callback() { 
      @Override 
      public void onCompleted(Response response) { 
       try { 
        FacebookRequestError fre = response.getError(); 
        if(fre != null) { 
         int errorCode = fre.getErrorCode(); 
         int requestCode = fre.getRequestStatusCode(); 
         if(errorCode == -1 && requestCode == -1) { 
          // probably no internet connection 
         } 
        } 
       } catch(Exception e) { 

       } 
      } 
     }); 
+0

你有沒有設法找到一個答案,你的問題? – Paul 2014-01-22 13:20:26

回答

1

這不是特定於Facebook API。檢查這個問題的答案:

Detect whether there is an Internet connection available on Android

我覺得這是一個重複的問題

+0

的確,我可以檢查互聯網連接狀態。但是,連接可能隨時丟失!一旦它丟失,並且響應返回錯誤,我想知道它是否沒有互聯網連接錯誤或其他Facebook錯誤。 – jclova 2013-05-03 15:40:37