skip to Main Content

I am trying to implement RTM in my app, I followed the official document step by step but when I try to login to the RTM server (using the App ID only method) nothing happens and the code that I implement based on the login never get implemented, I have looked in the agorartm.log file and found that the initialization of the rtmClient is successful but I don’t see anything about the login to the rtmClient and when I look in the usage page of my project I see that there is a one user in the Daily Active Users of the RTM but this just appears the next day I login not in the same day which is weird.

-here is the method I use to initialize the rtmClient and login to it :

private void loginToRtm(String uid,RtmLoginCallback rtmLoginCallback)
    {
    String appId = getString(R.string.AGORA_APP_ID);
    try
    {
     /*Initializing RtmClient*/
     rtmClient = RtmClient.createInstance(this, appId, new RtmClientListener() {
        @Override
        public void onConnectionStateChanged(int i, int i1) {

        }

      @Override
      public void onMessageReceived(RtmMessage rtmMessage, String s) {

        }
    @Override
    public void onImageMessageReceivedFromPeer(RtmImageMessage rtmImageMessage, String s) {

    }

    @Override
    public void onFileMessageReceivedFromPeer(RtmFileMessage rtmFileMessage, String s) {

    }

    @Override
    public void onMediaUploadingProgress(RtmMediaOperationProgress rtmMediaOperationProgress, long l) {

    }

    @Override
    public void onMediaDownloadingProgress(RtmMediaOperationProgress rtmMediaOperationProgress, long l) {

    }

    @Override
    public void onTokenExpired() {

    }

    @Override
    public void onPeersOnlineStatusChanged(Map<String, Integer> map) {

    }
});

}

catch (Exception e)
{
    throw new RuntimeException("RTM initialization failed!");
}

//Login to rtmClient
rtmClient.login(null, uid, new ResultCallback<Void>() {
    @Override
    public void onSuccess(Void aVoid) {

        rtmLoginCallback.rtmLoginOnCallback();

        Toast.makeText(context, uid + "Successful login to RTM", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFailure(ErrorInfo errorInfo) {

        rtmLoginCallback.rtmLoginOnCallback();

        Toast.makeText(context, uid + "failed to login to RTM"+errorInfo.toString(), Toast.LENGTH_SHORT).show();

        Log.d("RTM_LOGIN : ","Failed");
    }
});
}

-here are the permission I used in my manifest file:

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

-here is my agorartm.log file :

     INFO    2021-09-02T10:45:48:860   4775; Agora Logger Started
        INFO    2021-09-02T10:45:48:860   4775; Agora SDK ver 1.4.7 build 538, built on Jul 15 2021 20:46:30
        INFO    2021-09-02T10:45:

48:860   4775; Agora SDK git ver:480914647 and branch:HEAD
    INFO    2021-09-02T10:45:48:860   4845; set_thread_priority returns 1
    INFO    2021-09-02T10:45:48:861   4775; initialize plugin manager
    INFO    2021-09-02T10:45:48:861   4775; built-in encryption is enabled
    INFO    2021-09-02T10:45:48:862   4775; built-in ssl is enabled
    INFO    2021-09-02T10:45:48:862   4775; use event engine
    INFO    2021-09-02T10:45:48:864   4775; CacheManager: save cache to storage elapsed 2
    INFO    2021-09-02T10:45:48:864   4775; create agora service
    INFO    2021-09-02T10:45:48:864   4775; platform is LINUX
    INFO    2021-09-02T10:45:48:865   4775; platform is ANDROID
    INFO    2021-09-02T10:45:48:865   4775; [xdump] init enable:1, dumpfile:1
    INFO    2021-09-02T10:45:48:873   4775; create rtm service, count:1
    INFO    2021-09-02T10:45:48:874   4775; [rtm-API] rtm service initialize
    INFO    2021-09-02T10:45:48:874   4775; [rtm-API] rtm start service
    INFO    2021-09-02T10:45:48:875   4846; AgoraServiceThread Thread started: 0x78a9bc92a0
    INFO    2021-09-02T10:45:48:921   4846; The selected AP IPs are 101.132.108.165,123.56.235.221,.
    INFO    2021-09-02T10:45:48:921   4846; The selected AP IPs are 2406:da14:97f:4701:52:194:158:59,112.126.96.46,2600:1f18:64ea:9401:50:17:126:121,106.14.12.130,118.190.148.38,47.107.39.93,.
    INFO    2021-09-02T10:45:48:921   4846; [ap] queryDns normal domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:921   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:921   4846; [cm] queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:921   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:923   4846; [ap] queryDns TLS domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:923   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:923   4846; [cm] queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:923   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:924   4854; AgoraRtmThread Thread started: 0x7889ce60e0
    INFO    2021-09-02T10:45:48:925   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:925   4846; The selected AP IPs are 123.56.235.221,101.132.108.165,.
    INFO    2021-09-02T10:45:48:925   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,47.107.39.93,2406:da14:97f:4701:52:194:158:59,112.126.96.46,118.190.148.38,106.14.12.130,.
    INFO    2021-09-02T10:45:48:925   4846; [ap] queryDns normal domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [base_context]queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [cm] queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [base_context]queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [ap] queryDns TLS domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [base_context]queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [cm] queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:925   4846; [base_context]queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:926   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:926   4846; The selected AP IPs are 101.132.108.165,123.56.235.221,.
    INFO    2021-09-02T10:45:48:926   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,47.107.39.93,2406:da14:97f:4701:52:194:158:59,112.126.96.46,106.14.12.130,118.190.148.38,.
    INFO    2021-09-02T10:45:48:926   4846; [ap] queryDns normal domain is ap1.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [base_context]queryDns domain is ap1.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [cm] queryDns domain is ap1.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [base_context]queryDns domain is ap1.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [ap] queryDns TLS domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [cm] queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:926   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:926   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:926   4846; The selected AP IPs are 123.56.235.221,101.132.108.165,.
    INFO    2021-09-02T10:45:48:926   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,118.190.148.38,2406:da14:97f:4701:52:194:158:59,47.107.39.93,106.14.12.130,112.126.96.46,.
    INFO    2021-09-02T10:45:48:926   4846; [ap] queryDns normal domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [cm] queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [ap] queryDns TLS domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [cm] queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:927   4846; The selected AP IPs are 101.132.108.165,123.56.235.221,.
    INFO    2021-09-02T10:45:48:927   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,106.14.12.130,2406:da14:97f:4701:52:194:158:59,118.190.148.38,112.126.96.46,47.107.39.93,.
    INFO    2021-09-02T10:45:48:927   4846; [ap] queryDns normal domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [cm] queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap4.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [ap] queryDns TLS domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [cm] queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:927   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 123.56.235.221,101.132.108.165,.
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,106.14.12.130,2406:da14:97f:4701:52:194:158:59,47.107.39.93,118.190.148.38,112.126.96.46,.
    INFO    2021-09-02T10:45:48:928   4846; [ap] queryDns normal domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [cm] queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [ap] queryDns TLS domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [cm] queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap1-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 123.56.235.221,101.132.108.165,.
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 2600:1f18:64ea:9401:50:17:126:121,106.14.12.130,2406:da14:97f:4701:52:194:158:59,118.190.148.38,112.126.96.46,47.107.39.93,.
    INFO    2021-09-02T10:45:48:928   4846; [ap] queryDns normal domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [cm] queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [ap] queryDns TLS domain is ap2-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap2-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [cm] queryDns domain is ap2-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4846; [base_context]queryDns domain is ap2-tls.agora.io
    INFO    2021-09-02T10:45:48:928   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 101.132.108.165,123.56.235.221,.
    INFO    2021-09-02T10:45:48:928   4846; The selected AP IPs are 2406:da14:97f:4701:52:194:158:59,112.126.96.46,2600:1f18:64ea:9401:50:17:126:121,106.14.12.130,47.107.39.93,118.190.148.38,.
    INFO    2021-09-02T10:45:48:929   4846; [ap] queryDns normal domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [cm] queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap5.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [ap] queryDns TLS domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [cm] queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap3-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:929   4846; The selected AP IPs are 101.132.108.165,123.56.235.221,.
    INFO    2021-09-02T10:45:48:929   4846; The selected AP IPs are 2406:da14:97f:4701:52:194:158:59,118.190.148.38,2600:1f18:64ea:9401:50:17:126:121,47.107.39.93,112.126.96.46,106.14.12.130,.
    INFO    2021-09-02T10:45:48:929   4846; [ap] queryDns normal domain is ap2.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap2.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [cm] queryDns domain is ap2.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap2.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [ap] queryDns TLS domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [cm] queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:929   4854; [area_code] area status change
    INFO    2021-09-02T10:45:48:929   4846; The selected AP IPs are 123.56.235.221,101.132.108.165,.
    INFO    2021-09-02T10:45:48:929   4846; The selected AP IPs are 2406:da14:97f:4701:52:194:158:59,112.126.96.46,2600:1f18:64ea:9401:50:17:126:121,118.190.148.38,106.14.12.130,47.107.39.93,.
    INFO    2021-09-02T10:45:48:929   4846; [ap] queryDns normal domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [cm] queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:929   4846; [base_context]queryDns domain is ap3.agora.io
    INFO    2021-09-02T10:45:48:930   4846; [ap] queryDns TLS domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:930   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:930   4846; [cm] queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:930   4846; [base_context]queryDns domain is ap4-tls.agora.io
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.message.enable_advanced_e2e_scale from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.media.chunk_timeout from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_indian_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_south_america_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.encryption_level from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_na_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_africa_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_oceania_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_jp_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.message.enable_p0_scale from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_as_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_as_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_south_america_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_eur_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_cn_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_africa_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_oceania_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_tls_cn_area from TDS cache
    INFO    2021-09-02T10:45:48:930   4846; [CS]: found no value for key rtm.ip_indian_area from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [CS]: found no value for key rtm.ip_jp_area from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [CS]: found no value for key rtm.ip_eur_area from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [CS]: found no value for key rtm.link_port from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [CS]: found no value for key rtm.peer.end_call_enabled from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [CS]: found no value for key rtm.ip_tls_na_area from TDS cache
    INFO    2021-09-02T10:45:48:931   4846; [rtm-context] initialization started.
    INFO    2021-09-02T10:45:48:931   4846; [rtm-context] TLS-configuration started.
    INFO    2021-09-02T10:45:48:931   4846; [rtm-context] TLS-configuration succeed.
    INFO    2021-09-02T10:45:48:931   4846; [rtm-context] initialization succeed.

here is a link to a screenshot of my project usage page on the Agora Console showing that there is a user logged in

2

Answers


  1. Chosen as BEST ANSWER

    Just in case someone else faced this problem here is how I solved it :

    I Implemented the Agora RTM version 1.4.1 :

    'com.github.agorabuilder:rtm-sdk:1.4.1'
    

    instead of version 1.4.7 and then run my app on my device to find out that the reason of the problem is that Agora is implementing the Login method of the RTM inside another thread (outside from the main thread) so I got this exception :

    java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
    

    I search about this error and find a solution on this question : Can't toast on a thread that has not called Looper.prepare()

    I used the code provided by @nhoxbypass answer:

    runOnUiThread(new Runnable() {
      public void run() {
         final Toast toast = Toast.makeText(context, "GAME OVER!nScore: " + score, duration);
         toast.show();
      }
      });
    

    and the reason for this error was that I am making a toast outside of the main UI thread. so basically Agora handled this exception in the newer Version of their SDK so I was not able to see this error and to solve the problem , also they didn't mention that their methods are running outside of the main thread and in their documentation here: https://docs.agora.io/en/Real-time-Messaging/messaging_android?platform=Android#2-implement-the-logic-of-sending-and-receiving-messages they are making toasts inside the main thread which is totally wrong. later I returned to Agora RTM version 1.4.7 and run my app and I was able to login successfully.


  2. Looks like the documentation has been updated and uithread is added:

    https://docs.agora.io/en/Real-time-Messaging/messaging_android?platform=Android#2-implement-the-logic-of-sending-and-receiving-messages

                @Override
                public void onFailure(ErrorInfo errorInfo) {
                    CharSequence text = "User: " + uid + " failed to log in to the RTM system!" + errorInfo.toString();
                    int duration = Toast.LENGTH_SHORT;
                    runOnUiThread(new Runnable() {
                        public void run() {
                            Toast toast = Toast.makeText(getApplicationContext(), text, duration);
                            toast.show();
                        }
                    });
    
                }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search