Applozic chat in native Xamarin Android.
- Add DLLs as references in .net assemblies present in lib-dll folder.
Your Solution --> References --> Edit References --> .Net Assembly--> Browse and add all dlls from lib-dll folder.
Add Helper class ApplozicChatManager.cs in your main project.
Add activity, Services, permissions and meta-data required for applozic in your AndroidManifest.xml.
https://www.applozic.com/docs/android-chat-sdk.html#step-2-androidmanifest
i) Register/Login User:
ApplozicChatManger provide convenient method to register user with Applozic. You need to pass UserLoginListener reference which have login success/failure events callbacks.
private UserLoginListener loginListener = new UserLoginListener();
loginListener.OnRegistrationSucessHandler += OnRegistrationSucessHandler;// login success event
loginListener.OnRegistrationFailedHandler += OnRegistrationFailedHandler; //login failure event
ApplozicChatManager chatManager = new ApplozicChatManager(context);
chatManager.RegisterUser(<USER_ID>, <USER_DISPLAY_NAME>, <PASSWORD>, loginListener);
Event Callback:
void OnRegistrationSucessHandler( RegistrationResponse res, Context context)
{
System.Console.WriteLine("Successfully got callback in LoginActivity :" + res.Message);
}
void OnRegistrationFailedHandler(RegistrationResponse res, Java.Lang.Exception exception)
{
System.Console.WriteLine("Error:" + exception.Message);
}
NOTE: If you need to pass more information while doing registration, you can build Applozic user object and use below method for registration.
// Build Applozic users..
var user = new ApplozicUser();
user.DisplayName = displayName;
user.UserId = userId;
user.Password = password;
user.AuthenticationTypeId = new Short("1");
ApplozicChatManager chatManager = new ApplozicChatManager(context);
chatManager.RegisterUser( user,loginListener);
Use ApplozicChatManager methods to launch different type of chats:
i) Chat/Conversation List:
ApplozicChatManager chatManager = new ApplozicChatManager(context);
chatManager.LaunchChatList();
ii) One to One chat:
ApplozicChatManager chatManager = new ApplozicChatManager(context);
chatManager.LaunchChatWithUser(<RECEIVER_USER_ID>);
a) I do not have pushnotification setup:
i) Add ApplozicFirebaseIIDService.cs to your project.
ii) Declare the Receiver in the AndroidManifest.
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
android:exported="false" />
<!-- FCM COnfiguration -->
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
iii) Add google-service.json file to your project root directory, add to project and set build Build Action to GoogleServicesJson.
b) I have Pushnotification setup:
i) Send pushnotification token to Applozic server:
In your FirebaseInstanceIdService implementation class's OnTokenRefresh method send token to Applozic server.
ApplozicChatManager ChatManger = new ApplozicChatManager(context);
ChatManger.SendRegistrationToServer(refreshedToken);
Example:
public override void OnTokenRefresh()
{
var refreshedToken = FirebaseInstanceId.Instance.Token;
Log.Debug(TAG, "Refreshed token: " + refreshedToken);
//Send token to applozic server..
ApplozicChatManager ChatManger = new ApplozicChatManager(context);
ChatManger.SendRegistrationToServer(refreshedToken);
}
ii ) Receving and passing applozic notiifcations to SDK:
In your FirebaseMessagingService implementation class's OnMessageReceived method, check if notification belongs to Applozic.
//ADD below at top in OnMessageReceived.
if (message.Data.Count >0 )
{
if (MobiComPushReceiver.IsMobiComPushNotification(message.Data))
{
Log.Info(TAG, "Applozic notification processing...");
MobiComPushReceiver.ProcessMessageAsync(this, message.Data);
return;
}
}
Example*
public override void OnMessageReceived(RemoteMessage message)
{
Log.Debug(TAG, "From: " + message.From);
Log.Debug(TAG, "Notification Message Body: " + message.Data);
Log.Info(TAG, "Message data:" + message.Data);
if (message.Data.Count >0 )
{
if (MobiComPushReceiver.IsMobiComPushNotification(message.Data))
{
Log.Info(TAG, "Applozic notification processing...");
MobiComPushReceiver.ProcessMessageAsync(this, message.Data);
return;
}
}
}
ApplozicChatManager ChatManger = new ApplozicChatManager(context);
UserLogoutListener logoutListener = new UserLogoutListener();
logoutListener.OnLogoutSucessHandler += (context) =>
{
//Log out complete...
};
chatManager.Logout(logoutListener);
For possible UICustomisations, please visit our Android Documentaion page below:
https://www.applozic.com/docs/android-chat-sdk.html#customization