Randy Dalrymple HillyRoad, LLC Android Messaging Randy Dalrymple HillyRoad, LLC
Initial Problem Our app depends on sending daily status (I'm OK) Need to send status message between phones Must be cross-platform (Android/iOS) Cannot presume proximity (can be anywhere)
Prior Solution Android-only product works with SMS Android exposes interface to SMS inbox + events Quick, easy, ROBUST solution Fails completely with iOS (SMS interface hidden) → Will not work cross-platform
Additional Constraints Must not require application server (I don't have one) Must be low/no-cost RELIABILITY!
Options Considered Use Existing Solutions Dedicated server SMS (works only with Android) WhatsApp/Telegram (no API available) Dedicated server Violates constraint → Discard
Options Considered (Cont) Push Messaging Worth a look Other Chat Database
Mobile Push Messaging Internet-based Each platform (Apple, Google, Microsoft, etc.) has its own dedicated server Google: Firebase Cloud Messaging (FCM) Apple: Apple Push Messaging Server (APNS) Messages sent synchronously to device (more or less) Messages can originate from anywhere (other device, server, console)
More Mobile Push Messaging Often used for mass marketing/promotion Token provides device ID/app ID Payload is JSON dictionary format Relies on persistent, dedicated socket connection Google uses the Google Play Services socket for all services (Push, Maps, etc.) → Android device MUST have Google Play Services installed and running for push messaging
Google Firebase
Messaging Architecture 5 Application Server 5 Apple Push Notification Server (APN) Firebase/ Google Cloud Messaging Server 1 6 3 2 3 2 4 4 6 1 1. Register with messaging server 2. Receive token & connect to socket 3. Log in with token 4. Send push message 5. Request push notification 6. Receive push notification iOS Client Android Client
Application Server Role Authenticate user Handle push token for device Determine appropriate push server Accept push request from device Request push notification from push server Can use HTTP or XMPP (Preferred by APNS) APNS requires secure, persistent connection Handle errors/retries
Find Application Server BaaS Search criteria: Must provide complete solution Must be economical for small-scale deployment Should scale if product is successful Several products considered, but few are viable
Candidates Product Requires App Server Cost Satisfactory AWS Yes Free/Low No Firebase + Patch Free Applozic High after 30 days PubNub $149/mo for >100 users Layer Low Magnet High after 90 days AZStack Urban Airship QuickBlox Free for <20K users
QuickBlox Messaging Part of communications suite supporting messaging, chat, video chat, etc. Company based in London, UK Free tier Up to 20K users Allows 20 msg/sec. Beyond that, data ignored Libraries/sample apps for Android, iOS
QuickBlox Messaging Implementation Register application with Google, Apple Google is MUCH easier!!! Create QuickBlox account and register application Integrate QuickBlox framework in application
Google Console
QuickBlox Console
Problem 1: QB Integration Options Bare web API Most efficient, but most work (threading, etc.) Use QB framework Must analyze/understand framework more fully Sample app (includes framework) Easiest to implement quickly → Use this one!
Problem 2: How to Handle User ID QB User ID must be unique Users are unaware of underlying QB framework Users know each other only by name and phone number → Create anonymous QB User ID using phone number
Android QB Integration Required app functions Test for internet connection Create user ID for QuickBlox framework Register for remote notification Retrieve recipients' user IDs when sending message Send push message Handle received push message
Push Sample App Integration
MainActivity @Override protected void onResume() { super.onResume(); try { if (!Utils.isNetworkConnected(getApplicationContext())) { Utils.showAlert("No Internet", "Check your internet connection.", MainActivity.this); } else { qbManager = new QBManager(this.getApplicationContext()); qbManager.createSession(); } } catch (Exception e) { // sometimes throws exception even when connected Utils.showAlert("No Internet", "Check your internet connection.", MainActivity.this); } mSharedPreferences = getSharedPreferences(Utils.PREFS, MODE_PRIVATE); String org = mSharedPreferences.getString(Utils.PREF_IS_ORGANIZER, null); if (org == "true") { createChatGroup(); } }
MainActivity
QBManager
MainActivity
MainActivity
CoreGcmPushListenerService public abstract class CoreGcmPushListenerService extends GcmListenerService { private static final String TAG = CoreGcmPushListenerService.class.getSimpleName(); @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString(GcmConsts.EXTRA_GCM_MESSAGE); Log.v(TAG, "From: " + from); Log.v(TAG, "Message: " + message); if (ActivityLifecycle.getInstance().isBackground()) { showNotification(message); } logCheckInMessage(message); sendPushMessageBroadcast(message); protected abstract void showNotification(String message); protected abstract void sendPushMessageBroadcast(String message); protected abstract void logCheckInMessage(String message);
Results Messaging implemented in Android (appx. 35 hrs) and iOS (appx. 30 hrs) Successfully sent push messages between Android, iOS However.......
More Results Messaging not sufficiently reliable for safety/security application Google, Apple servers maintain 1-element queue per application iOS does not handle silent push cleanly During testing, Apple server offline for 24 hours We need to try something else—Chat, DB or something else!
Misc: QuickBlox Statistics
Misc: QuickBlox Console Push
Selected References https://www.raywenderlich.com/126098/top-5-parse-alternatives http://www.androidbegin.com/blog/list-best-android-backend-service-baas-provider/ http://stackoverflow.com/questions/11508613/how-does-push-notification-technology-work-on-android https://firebase.google.com/docs/cloud-messaging/server https://www.whatsapp.com/faq/android/28000012 http://pushproviders.com/ https://aws.amazon.com/sns/ https://firebase.google.com/ https://layer.com/ https://www.applozic.com/price.html http://quickblox.com/developers/SimpleSample-messages_users-android