2013-05-04 40 views
0

如何糾正錯誤「方法getErrorCodeName()未定義爲類型MulticastResult」?我用下面的代碼使用GCM的android代碼中的getErrorCodeName()錯誤

  MulticastResult result = sender.send(message, androidTargets, 1); 

      if (result.getResults() != null) { 
       int canonicalRegId = result.getCanonicalIds(); 
       if (canonicalRegId != 0) { 
        // same device has more than on registration ID: update database 
       } 
      } else { 
       int error = result.getFailure(); 
       System.out.println("Broadcast failure: " + error); 
       String error_code_name = result.getErrorCodeName(); //Error is Here 
       if (error_code_name.equals(Constants.ERROR_NOT_REGISTERED)) { 
         // application has been removed from device - unregister database or remove from database 
        } 
      } 

在此先感謝!

回答

1

你想這樣做:

result.getResults().get(0).getErrorCodeName(); 

或類似的東西:

for(Result r : result.getResults()){ 
    if (Constants.ERROR_NOT_REGISTERED.equals(r)) { 
      // application has been removed from device - unregister database or remove from database 
    } 
} 

API文檔:

http://developer.android.com/reference/com/google/android/gcm/server/MulticastResult.html http://developer.android.com/reference/com/google/android/gcm/server/Result.html

+0

太謝謝你了。它的工作 – Sakthimuthiah 2013-05-06 04:21:16