2012-11-24 1 views
0

점수 수 없습니다 : 그것은 항상 새로운 사용자를 제출하지Scoreloop가 안드로이드 사용자를 제출하거나이 코드입니다

public class ProfileActivity extends Activity { 

private final static int DIALOG_PROGRESS = 0; 
private final static int DIALOG_SUCCESS = 1; 
private final static int DIALOG_ERROR = 2; 

private EditText usernameText; 
private EditText emailText; 

// saves the last error occurred, so we can read it in onPrepareDialog() 
String dialogErrorMsg = ""; 
String dialogSuccessMsg = ""; 


public void onResume() { 
    super.onResume(); 

    // here we fetch the user's profile data from Scoreloop to fill in 
    // the text fields 

    // first, a request observer... 
    RequestControllerObserver observer = new RequestControllerObserver() { 


     public void requestControllerDidReceiveResponse(RequestController requestController) { 
      UserController userController = (UserController)requestController; 
      dismissDialog(DIALOG_PROGRESS); 

      // insert values into text fields 
      User user = userController.getUser(); 
      usernameText.setText(user.getLogin()); 
      emailText.setText(user.getEmailAddress()); 
     } 


     public void requestControllerDidFail(RequestController aRequestController, Exception anException) { 
      // the profile could not be loaded :(
      dismissDialog(DIALOG_PROGRESS); 

      // show some error message 
      dialogErrorMsg = "خطأ في تحميل الملف الشخصي"; 
      showDialog(DIALOG_ERROR); 
     } 
    }; 

    // here's the UserController doing our work to update the profile data 
    UserController userController = new UserController(observer); 

    // show progress dialog 
    showDialog(DIALOG_PROGRESS); 

    // and fire the request 
    userController.loadUser(); 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // load the layout 
    setContentView(R.layout.profile); 

    // find our text fields 
    usernameText = (EditText) findViewById(R.id.text_username); 
    emailText = (EditText) findViewById(R.id.text_email); 

    // set up click handler for the save button 
    ((Button) findViewById(R.id.button_save_profile)).setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 

      // get the current User 
      User user = Session.getCurrentSession().getUser(); 

      // update his values 
      user.setLogin(usernameText.getText().toString()); 
      user.setEmailAddress(emailText.getText().toString()); 

      // set up a request observer 
      RequestControllerObserver observer = new RequestControllerObserver() { 


       public void requestControllerDidReceiveResponse(RequestController aRequestController) { 
        dismissDialog(DIALOG_PROGRESS); 

        dialogSuccessMsg = "تم تحميل الملف الشخصي بنجاح"; 

        showDialog(DIALOG_SUCCESS); 
       } 


       public void requestControllerDidFail(RequestController controller, Exception exception) { 
        dismissDialog(DIALOG_PROGRESS); 

        // Error handling has to account for many different types of 
        // failures... 

        if(exception instanceof RequestControllerException) { 

         RequestControllerException ctrlException = (RequestControllerException) exception; 

         if(ctrlException.hasDetail(RequestControllerException.DETAIL_USER_UPDATE_REQUEST_EMAIL_TAKEN)) { 
          // this case is not quite a fatal error. if the email address is already 
          // taken, an email will be sent to it to allow the user to link this device 
          // with his account. 
          // that's why we'll show a success dialog in this case. 
          dialogSuccessMsg = "تم إستخدام الأميل من قبل شخص آخر"; 
          showDialog(DIALOG_SUCCESS); 
         } 
         else { 
          // in any of these cases it's an error: 

          dialogErrorMsg= ""; 
          // email may be invalid 
          if(ctrlException.hasDetail(RequestControllerException.DETAIL_USER_UPDATE_REQUEST_INVALID_EMAIL)) { 
           dialogErrorMsg += "خطأ في الأميل"; 
          } 

          // username may be invalid, taken or too short 
          if(ctrlException.hasDetail(RequestControllerException.DETAIL_USER_UPDATE_REQUEST_USERNAME_TAKEN)) { 
           dialogErrorMsg += "تم إستخدام الأسم من قبل شخص آخر"; 
          } 
          else if(ctrlException.hasDetail(RequestControllerException.DETAIL_USER_UPDATE_REQUEST_USERNAME_TOO_SHORT)) { 
           dialogErrorMsg += "الأسم قصير جدا"; 
          } 
          else if(ctrlException.hasDetail(RequestControllerException.DETAIL_USER_UPDATE_REQUEST_INVALID_USERNAME)) { 
           dialogErrorMsg += "الأسم غير صالح للإستخدام"; 
          } 

          showDialog(DIALOG_ERROR); 
         } 
        } 
        else { 
         // generic Exception 
         dialogErrorMsg = exception.getLocalizedMessage(); 
         showDialog(DIALOG_ERROR); 
        } 


        // update displayed values 
        User user = ((UserController)controller).getUser(); 
        usernameText.setText(user.getLogin()); 
        emailText.setText(user.getEmailAddress()); 

       } 
      }; 

      // with our observer, set up the request controller 
      UserController userController = new UserController(observer); 

      // pass the user into the controller 
      userController.setUser(user); 

      showDialog(DIALOG_PROGRESS); 

      // submit our changes 
      userController.submitUser(); 

     } 
    }); 
} 



// handler to create our dialogs 
@Override 
protected Dialog onCreateDialog(final int id) { 
    switch (id) { 
    case DIALOG_PROGRESS: 
     return ProgressDialog.show(ProfileActivity.this, "", "جاري التحميل"); 
    case DIALOG_ERROR: 
     return (new AlertDialog.Builder(this)) 
      .setPositiveButton("إغلاق", null) 
      .setMessage("") 
      .create(); 
    case DIALOG_SUCCESS: 
     return (new AlertDialog.Builder(this)) 
      .setPositiveButton("إغلاق", null) 
      .setMessage("") 
      .create(); 
    } 
    return null; 
} 

// handler to update the success and error dialog with the corresponding message 
@Override 
protected void onPrepareDialog(int id, Dialog dialog) { 
    switch (id) { 
    case DIALOG_ERROR: 
     AlertDialog errorDialog = (AlertDialog)dialog; 
     errorDialog.setMessage(dialogErrorMsg); 
     break; 
    case DIALOG_SUCCESS: 
     AlertDialog successDialog = (AlertDialog)dialog; 
     successDialog.setMessage(dialogSuccessMsg); 
     break; 
    } 
} 

} 

. 아무 이유없이 그리고 나는 이미 내 메인 화면에서 그것을 초기화합니다.

Client.init(this, secret, null); 

또한 내 보조 폴더에 socreloop.properties를 복사했습니다.

새 점수를 제출할 때도 동일한 문제가 발생합니다. 제출하지 않을 것입니다. 및 감사합니다.

답변

0

제 경우에는 에뮬레이터에서 테스트하여 새 사용자를 추가하는 데 시간이 오래 걸리고 에뮬레이터에서 새 사용자를 추가하지 못한 경우에도 안드로이드 장치에서 테스트 해보십시오.

+0

동일한 문제가 발생했습니다. – Taha

+0

잘하면 귀하의 응용 프로그램에서 인터넷 사용 권한을 추가했습니다 –

+0

예 내 응용 프로그램에서 인터넷 사용 권한이 있습니다. – Taha

관련 문제