Webim SDK sample
A sample for represent interaction with Webim Mobile SDK. Supported from Android API 15
Version
Installation
Add to your build.gradle dependencies:
compile 'com.webim.sdk:webimclientsdkandroid:2+'
May require (SDK is using this libraries. By default, they will be added to your project automatically, but in special cases you need to add them manually):
compile 'com.google.android.gms:play-services-gcm:7.8.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
Required permission:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Usage
WebimSdk contains 2 types of session:
- Online chat (WMSession)
- Offline chats (WMOfflineSession)
Important!
Not guaranteed stable work with retrofit 2.0.0-beta or higher.
If a user needs an immediate response from an operator, please, use Online chat.
If a user just leave request, and an operator can answer later (e.g. in one week), please, use Offline chats.
Development
#####Online chat Online chats are simpler for implementation. You can see example in OnlineChatFragment. All you need is:
- Create WMSession.WMSessionDelegate.
- Overwrite event methods (e.g. sessionDidChangeSessionStatus, sessionDidStartChat, sessionDidReceiveMessage and others)
- Create WMSession using Android Context, Webim account and location (please, contact Webim Support for more info about this params), and WMSessionDelegate.
- Call startSession() from WMSession object.
After this steps, you will receive events in WMSessionDelegate and can perform any actions with WMObjects(WMChat, WMOperator, WMMessage and e.t.c.).
For interaction with Online Chat uses other methods from WMSession (e.g. startChat, sendMessage, sendImage, closeChat and others).
If you want to stop communication with Webim service, please, call stopSession (e.g onStop() or onDestroy()).
#####Offline Chats WMOfflineSession can contain 0+ chats.
So, default imp is containing 2 Views
- Chats Chooser View (OfflineFragment)
- Chat View (OfflineChatFragment)
Creation of WMOfflineSession is the same as WMSession, but it doesn't contain global delegate.
- To receive cached data use method getOfflineChats()
- To receive last data from server use getHistoryForced() (boolean param forced means that data will be updated from beginning of the session. Please use cached data with forced = false - this will reduce internet traffic, and request only last changes from server.)
- Each request has its own callback (sendMessage, sendImage, deleteCaht and e.t.c.), so you can interact with them separately.
Offline chat can create messages and chats locally, without an internet connection. For sync data with Webim Service please use method sendUnsentRequests from WMOfflineSession.
###Push Notification By default, online and offline sessions have GCM interaction.
For enable push-notification system, please add default realization See android samples and GcmIntentService with GcmBroadcastReceiver.
To make WebimSdk collaborate with push call static method WMSession.onPushMessage (see GcmIntentService). Don't forget about requirement of permissions for GCM.
Todo's
- Add info about "Synchronized requests" in WMOfflineChats.
License
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.