/**
   * register to the server
   *
   * @param context Activity or Service context
   * @param regId gcmId registered from Google
   */
  public static boolean register(Context context, String regId) {

    String serverUrl = ServerUrl.SERVER_URL_GCM_REGISTER();
    String uid = PreferenceControl.getUID();

    try {
      DefaultHttpClient httpClient = HttpSecureClientGenerator.getSecureHttpClient();
      HttpPost httpPost = new HttpPost(serverUrl);
      httpClient
          .getParams()
          .setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
      MultipartEntityBuilder builder = MultipartEntityBuilder.create();
      builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
      builder.addTextBody("uid", uid);
      builder.addTextBody("regId", regId);

      httpPost.setEntity(builder.build());
      boolean result = uploader(httpClient, httpPost);
      GCMRegistrar.setRegisteredOnServer(context, result);
      return result;
    } catch (Exception e) {
      GCMRegistrar.setRegisteredOnServer(context, false);
      return false;
    }
  }
예제 #2
0
 public UserLevelCollector(Context context) {
   this.context = context;
   SERVER_URL_RANK_ALL = ServerUrl.SERVER_URL_RANK_ALL();
   SERVER_URL_RANK_WEEK = ServerUrl.SERVER_URL_RANK_WEEK();
   responseHandler = new BasicResponseHandler();
 }