0

如何纠正“MulticastResult 类型的方法 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
                     }
            }

提前致谢 !

4

1 回答 1

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

于 2013-05-04T10:04:18.547 回答