コード例 #1
0
  /**
   * 收到push消息后做重连,重新连接融云
   *
   * @param token
   */
  private void reconnect(String token) {

    mDialog = new LoadingDialog(this);
    mDialog.setCancelable(false);
    mDialog.setText("正在连接中...");
    mDialog.show();

    try {
      RongIM.connect(
          token,
          new RongIMClient.ConnectCallback() {

            @Override
            public void onTokenIncorrect() {}

            @Override
            public void onSuccess(String userId) {
              mHandler.post(
                  new Runnable() {
                    @Override
                    public void run() {
                      mDialog.dismiss();
                      Intent intent = getIntent();
                      if (intent != null) {
                        enterFragment(intent);
                      }
                    }
                  });
            }

            @Override
            public void onError(RongIMClient.ErrorCode e) {
              mHandler.post(
                  new Runnable() {
                    @Override
                    public void run() {
                      mDialog.dismiss();
                    }
                  });
            }
          });
    } catch (Exception e) {
      mHandler.post(
          new Runnable() {
            @Override
            public void run() {
              mDialog.dismiss();
            }
          });
      e.printStackTrace();
    }
  }
コード例 #2
0
  /**
   * 收到push消息后做重连,重新连接融云
   *
   * @param token
   */
  private void reconnect(
      final String token,
      final String conversation,
      final String conversationType,
      final String targetId) {

    mDialog.setText("正在连接中...");
    mDialog.show();
    try {
      RongIM.connect(
          token,
          new RongIMClient.ConnectCallback() {
            @Override
            public void onTokenIncorrect() {
              Log.e(TAG, "--onTokenIncorrect---");
            }

            @Override
            public void onSuccess(String userId) {
              if (mDialog != null) mDialog.dismiss();
              if (conversation.equals("conversation")) {
                if (RongIM.getInstance() != null
                    && RongIM.getInstance().getRongIMClient() != null) {

                  RongIM.getInstance()
                      .getRongIMClient()
                      .getConversation(
                          Conversation.ConversationType.valueOf(conversationType),
                          targetId,
                          new RongIMClient.ResultCallback<Conversation>() {
                            @Override
                            public void onSuccess(Conversation conversation) {

                              if (conversation != null) {

                                if (conversation.getLatestMessage()
                                    instanceof ContactNotificationMessage) {
                                  startActivity(
                                      new Intent(MainActivity.this, NewFriendListActivity.class));
                                } else {
                                  Uri uri =
                                      Uri.parse("rong://" + getApplicationInfo().packageName)
                                          .buildUpon()
                                          .appendPath("conversation")
                                          .appendPath(conversationType)
                                          .appendQueryParameter("targetId", targetId)
                                          .build();
                                  Intent intent = new Intent(Intent.ACTION_VIEW);
                                  intent.setData(uri);
                                  startActivity(intent);
                                }
                              }
                            }

                            @Override
                            public void onError(RongIMClient.ErrorCode e) {}
                          });
                }
              }
            }

            @Override
            public void onError(RongIMClient.ErrorCode e) {
              mDialog.dismiss();
            }
          });
    } catch (Exception e) {
      mDialog.dismiss();
      e.printStackTrace();
    }
  }
コード例 #3
0
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.app_sign_in_bt: // 登录
        userName = mUserNameEt.getEditableText().toString();
        String passWord = mPassWordEt.getEditableText().toString();
        String name = null;
        if (TextUtils.isEmpty(userName) || TextUtils.isEmpty(passWord)) {
          WinToast.toast(this, R.string.login_erro_is_null);
          return;
        }

        if (mDialog != null && !mDialog.isShowing()) {
          mDialog.show();
        }
        // 发起登录 http请求 (注:非融云SDK接口,是demo接口)
        if (DemoContext.getInstance() != null) {
          // 如果切换了一个用户,token和 cookie 都需要重新获取
          if (DemoContext.getInstance() != null) {
            name =
                DemoContext.getInstance()
                    .getSharedPreferences()
                    .getString("DEMO_USERNAME", "DEFAULT");
          }

          if (!userName.equals(name)) {

            loginHttpRequest =
                DemoContext.getInstance().getDemoApi().login(userName, passWord, this);
            isFirst = true;
          } else {
            isFirst = false;
            String cookie =
                DemoContext.getInstance()
                    .getSharedPreferences()
                    .getString("DEMO_COOKIE", "DEFAULT");
            String token =
                DemoContext.getInstance().getSharedPreferences().getString("DEMO_TOKEN", "DEFAULT");
            if (!cookie.equals("DEFAULT") && !token.equals("DEFAULT")) {
              httpGetTokenSuccess(token);
            } else {
              loginHttpRequest =
                  DemoContext.getInstance().getDemoApi().login(userName, passWord, this);
            }
          }
        }

        break;
      case R.id.de_left: // 注册
      case R.id.de_login_register: // 注册
        Intent intent = new Intent(this, RegisterActivity.class);
        startActivityForResult(intent, REQUEST_CODE_REGISTER);
        break;
      case R.id.de_login_forgot: // 忘记密码
        WinToast.toast(this, "忘记密码");
        break;
      case R.id.de_right: // 忘记密码
        Intent intent1 = new Intent(this, RegisterActivity.class);
        startActivityForResult(intent1, REQUEST_CODE_REGISTER);
        break;

      case R.id.app_username_et:
      case R.id.app_password_et:
        Message mess = Message.obtain();
        mess.what = HANDLER_LOGIN_HAS_FOCUS;
        mHandler.sendMessage(mess);
        break;
    }
  }