Installation
Add maven arguments to gradle.properties
Copy m_contextUrl=...
m_user=...
m_password=...
Add maven repository to the application level build.gradle
Copy allprojects {
repositories {
jcenter()
maven {
url "${m_contextUrl}/libs-release"
credentials {
username = "${m_user}"
password = "${m_password}"
}
}
}
}
Add the class path dependency to the project level build.gradle
(Module:app)
Copy dependencies {
compile(group: 'com.imbee.core', name: 'imbeecorelib', version: '0.9.14', ext: 'aar') {
transitive = true;
}
}
Add the class path dependency to the project level build.gradle
(Module:app)
Copy buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:3.7.2"
}
}
Apply the realm-android
plugin to the top of the application level build.gradle
Copy apply plugin: 'realm-android'
Configuration
You need add internet permission to AndroidManifest:
Copy <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
In onCreate()
on an application subclass, you must initialize:
Copy @ Override
public void onCreate() {
super . onCreate ();
IMbeeCore . init ( this );
}
In onCreated()
on an activity subclass, you can prepare, delete an existing user, configure ...
Copy @ Override
public void onCreate() {
super . onCreate ();
// Servers configuration
final String WS_URL = "..." ;
final String XMPP_URL = "..." ;
final String apikey = "..." ;
final String userIdsha = "..." ;
final String uniqueIdsha = "..." ;
final String hardwareId = "..." ;
final String platform = "android" ;
final String deviceName = "..." ;
final String osVersion = "..." ;
(new ExternalUserRegistration(apikey, uniqueIdsha, hardwareId, platform, deviceName, osVersion)).get(new Response.Listener() {
@ Override
public void onResponse( Object response) {
boolean previouslyRegistered = ( boolean ) response;
startXmpp() ;
( new ChatCreate(userIdsha) ) . get ( new Response . Listener () {
@ Override
public void onResponse( Object response) {
ChatCreateResponse chatCreateResponse = (ChatCreateResponse) response;
String CONVERSATION_ID = chatCreateResponse . conversationId ;
boolean previouslyCreated = chatCreateResponse . previouslyCreated ;
Intent intent = new Intent() ;
intent . setAction ( "chatListDone" );
intent . putExtra ( "conversationId" , CONVERSATION_ID);
IMbeeUI . getLocalBroadcastManager () . sendBroadcast (intent);
}
} , null );
}
} , null );
}
public void startXmpp() {
Realm realm = IMbeeCore . getRealm ();
Profile profile = IMbeeCore . getProfile (realm);
IMbeeCore . xmppSetCredentials (profile);
IMbeeCore . xmppStartService ( this );
realm . close ();
}
New quick configuration
Now you can with the new function
Copy UserAndChatCreation( Context context , String apikey , String uniqueIdsha ,
String hardwareId , String platform , String deviceName ,
String osVersion ,
String ws_url , String xmpp_url ,
String idsha_bot , boolean production)
create both your user and connect to a conversation in one step:
Copy @ Override
public void onCreate() {
super . onCreate ();
// Servers configuration
final String WS_URL = "..." ;
final String XMPP_URL = "..." ;
final String apikey = "..." ;
final String userIdsha = "..." ;
final String uniqueIdsha = "..." ;
final String hardwareId = "..." ;
final String platform = "android" ;
final String deviceName = "..." ;
final String osVersion = "..." ;
( new UserAndChatCreation( this , APIKEY , u_uniqueIdsha , u_hardwareId ,
u_platform , u_deviceName , u_osVersion , WS_URL , XMPP_URL ,
IDSHA_BOT , production) )
. get ( new UserAndChatCreateResponse . OnUserAndChatCreateListener () {
@ Override
public void onResponse( UserAndChatCreateResponse response) {
//You can now start your Chat Activity.
}
} , null );
}
Examples
Polling unread messages by conversation:
Copy Conversation c = ... ;
c . messages . getCountPendingReadMessages ();
Sending an invisible message:
Copy Text textContent = new Text() ;
textContent . text = "invisible message bla bla..." ;
IMbeeCore . sendMessageWithFlags (CONVERSATION_ID , IMMPFormat . TYPE_MESSAGE , textContent