Skip to content

Instantly share code, notes, and snippets.

@hieptl
Last active October 13, 2021 03:20
Show Gist options
  • Save hieptl/19b3a39cc7a2bc82f3d2efe9ece1245f to your computer and use it in GitHub Desktop.
Save hieptl/19b3a39cc7a2bc82f3d2efe9ece1245f to your computer and use it in GitHub Desktop.
LoginActivity.java - Init CometChat and Login to CometChat - Voice and Video Chat App - Android App
...
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
this.initCometChat();
}
...
private void initCometChat() {
AppSettings appSettings=new AppSettings.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(Constants.COMETCHAT_REGION).build();
CometChat.init(this, Constants.COMETCHAT_APP_ID, appSettings, new CometChat.CallbackListener<String>() {
@Override
public void onSuccess(String successMessage) {
UIKitSettings.setAuthKey(Constants.COMETCHAT_AUTH_KEY);
CometChat.setSource("uikit","android","java");
Toast.makeText(LoginActivity.this, "Initialized CometChat", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(CometChatException e) {
Toast.makeText(LoginActivity.this, "Failure to initialize CometChat", Toast.LENGTH_SHORT).show();
}
});
}
...
private void loginCometChat() {
if (this.loggedInUser != null && this.loggedInUser.getUid() != null) {
CometChat.login(this.loggedInUser.getUid(), Constants.COMETCHAT_AUTH_KEY, new CometChat.CallbackListener<User>() {
@Override
public void onSuccess(User user) {
Toast.makeText(LoginActivity.this, "Login Successfully", Toast.LENGTH_SHORT).show();
goToCometChatUI();
}
@Override
public void onError(CometChatException e) {
}
});
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment