Android SDK
This page gives you all of the documentation needed to integrate the 2mee Android SDK. This page will be updated with any changes or new features added to the SDK.
Last updated
This page gives you all of the documentation needed to integrate the 2mee Android SDK. This page will be updated with any changes or new features added to the SDK.
Last updated
This document will guide you through the example Appear2meeDemo app provided in the 2mee Android SDK showing how Face Messaging and rich text integration is achieved. This document refers to the sample Appear2meeDemo App. The sample code can be downloaded from https://www.2mee.com/SDK/Appear2meeSDKAndroid.zip Copy the link into a separate tab if it does not go to the page.
Messages are sent from the 2mee Platform using push notifications. The notification includes the url/s of files that are required to display the notification. These files must be downloaded by the device in order to present the notification. When the firebase push notification is received an attempt is made to download any required files. If the message file cannot be downloaded a fallback text is “posted” as the notification. This fallback text is included in the notification and is set by your Platform user.
These messages are displayed initially as notification and in app as “dialogs”. Touching video/image notifications will give a larger view of the image/video. A video or sound can be paused/restarted by tapping on the middle of the image/video. Tapping on outside the middle will “accept” the message, and tapping on the X in at the top right corner will dismiss the large view, returning to the dialog.
Face messages appear within the app in developer selected positions dependant on the face type, see below for details. A touch on the face itself will “accept” the message a swipe anywhere else will dismiss the message as will a tap outside the face area. A double tap on the face will pause/restart the message.
The Appear2mee SDK is accessed using the jitpack maven repository. To do this first add the repository in your root build.gradle at the end of repositories:
Then add the Appear2meeSDKAndroid to the dependencies in the app build.gradle file.
When building for android 12 / API 31 the app build.gradle file should also include compile options to allow target compatibility with Java version 11.
If you are using and older gradle and you cannot upgrade to version 7 you can use
And
But all future updates will be for gradle 7+
A 2mee enabled message app uses a number of components that are included in the SDK but must be given permission to use the AndroidManifest.xml file. These are the Appear2meeNotificationActivity that is called when a notification is selected. An internal JobService that downloads files. A broadcast receiver that is used to trigger the local notification at the correct time. Lastly the firebase messaging service that handles both incoming firebase notifications and deviceToken events to trigger sending the deviceToken to the 2mee Exchange.
Note: The Appear2meeNotificationActivity uses an openGL View. Apps by default allow openGL views, but if you app has hardwareAccelerated set to false, you will need to set it to true either for the whole app or just the Appear2meeNotificationActivity activity, in your AndroidManifest.xml.
There are also a number of permissions that need to be included in the manifest.
See the demo app manifest file to copy paste to your app.
In order to link the App to the exchange it needs a Client ID and a secret key. These are generated in the 2mee Exchange. In order for the 2mee Exchange to connect to the App on the device firebase cloud messaging server key, and the senderID are required by the exchange. The exchange uses the server key to authorise sending push notifications and the sundered is used to check that deviceTokens registered on the exchange are for the same project as the server key. See the Getting Started for details of accessing the exchange keys and how to add the server key and senderid (also called the project id). The project server key are found in your firebase settings for your project.
The Appear2mee SDK needs to be setup in the Application class. This is where initialisation and callbacks are set. This is to ensure that SDK is setup when a notification is opened. Many Android apps do not override the standard Application class, so you may need to create one. It is important to indicate in the AndroidManifest.xml file the class name of the Application class used.
Note, the use of the android:fullBackupContent=“@xml/my_backup_rules" this will be discussed later.
In any 2mee message app a connection to the 2mee Exchange is required. The exchange client id and secret key are generated on the 2mee exchange for each app administered on the exchange. If you are doing the exchange setup as well, see the 2mee Exchange Docs.
The init method Appear2mee.init is used allow the app to communicate with the exchange and respond to notifications. The function signature is public static <T extends Application & ResponseListenerCallback> void init(T app, String appear2meeID, String appear2meeKey). It requires the first argument to be of Application class which implements the Appear2mee.ResponseListenerCallback.
Note: All Appear2mee functions are class functions.
The default notification icons are 2mee png icons. To replace these icons you will need to name at least one image in your res/mipmap*** resources appear2mee_notification_icon, for the in notification icon. The status bar notification icon (which is normally white on transparent) is called appear2mee_notification_icon_small and should be included in your drawables. See an android icon maker to make this status bar icon.
The FirebaseMessagingService is used to both handle device tokens registration on the 2mee Exchange and also receiving then forwarding firebase messages. If you have not used the FirebaseMessagingService before you should read the documentation at https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessagingService. Pay close attention to the manifest requirements. Note the older firebase api had a separate FirebaseInstanceIdService, that service is now incorporated into the FirebaseMessagingService.
If you are not familiar with firebase then you should read the requirements for android setup at https://firebase.google.com/docs/android/setup. If you are setting up a new project you will need to add the google-services.json to your project. This is found in your firebase project settings.
The app requires FirebaseMessageServices class, see the example app. The onNewToken method should contain a Appear2mee call to registerDeviceToken. This method will register the app on the exchange.
Push notifications are handled in the FirebaseMessagingService onMessageReceived, exchange messages are data messages, and are handled using the Appear2mee.onMessageReceived function.
The Appear2mee.onMessageReceived determines if the message is from the 2mee Exchange. If it is not a 2mee Exchange notification the function will return false and pass control back to allow the developer to handle the notification. If the function returns true the notification has been fully processed by the SDK.
On receiving the notification the Appear2mee SDK will download any files associated with the message (if it has download permission) and will schedule an internal alarm at the play time the message has defined. If the message has expired the message will be ignored. The alarm when triggered will send a local notification.
Important: If permission is not granted for write/read file access the app cannot download any files associated with the message from the exchange.
Remote push notifications are sent by the 2mee Exchange to your app, these notifications do not include an alert so that on receipt they are silent. The Appear2mee SDK has to process these notifications, downloaded any files and schedule an internal alarm at the play time. When the alarm is triggered the Appear2mee SDK displays a local notification
When the user interacts with the local notification it can be dismissed or “accepted”. If the notification was accepted the app will to come into the foreground or launch, and the Appear2meeNotificationActivity is started. When Appear2meeNotificationActivity launches it calls the appear2meeResponseListener callback function in the Application class (which must implement Appear2mee.ResponseListenerCallback). The appear2meeResponseListener callback returns a Appear2mee.ResponseListener, which determines what actions are taken when the user dismisses/accepts the dialog or face message. For example,
In the Appear2meeNotificationActivity images/Animations/Videos are shown with a simple popup dialog with dismiss and accept buttons. A face message is shown with a popover where a swipe action outside the face will be a dismiss and a touch on the face will be an accept. These “dialog” responses will call the appropriate dismiss or accept listener action function.
The dismissAction/acceptAction functions are called with a dictionary of key/values that were attached to the notification in the 2mee Exchange. Typically they can be used to perform some action based on the values present. For example, move to a page on the app {“page”:”sports/mens/shorts”}.
Note: Notifications can be cleared in the notification drawer, in which case the app does not get any response.
Apps that target Android 6.0 (API level 23) or higher are automatically enabled for Auto Backup. However some of the Appear2mee SDK app data should not be backed up. It includes the device token and device specific data connecting the device to the 2mee Exchange. If a new device uses a backup it can lead to two devices connected to the same device entry and potentially a clash of settings. The userID and tags are stored in a different sharepref, and will be backed up. These are the links between the app and the actual user.
In order to avoid this the demo app uses an option to define which preferences are backed up.
In resources a file res/xml/my_backup_rules.xml defines which data to exclude from backup.
After completing the App setup the app will be functional. There are other options that you might need to setup within the app.
Many apps are linked to a separate system and have some kind of user identity. The SDK allows the app to store a userID. The 2mee exchange can return reports based on a user supplied userID. This id should be a string and can be supplied after the init of the Appear2mee SDK using the class method Appear2mee.registerUserID. If a userID is not supplied the device token is used as the userID. In the demo app there is a button [userID] that can be used to open a text dialog to input a userID.
In order to customise face messages to an individual user, a tag system is used. This allows the developer to send tags to the exchange that are indicative of the content to be sent to a particular user. The 2mee Exchange uses the tags set to a corresponding deviceToken to determine which messages a device should be sent.
Tags can be set using internal logic, for example game level, previous activity etc. Alternatively tags can be sent to an individual device, by a custom scheme of the developers choosing, and should then be forward to the exchange via the tags system.
Tags are represented as a dictionary (Map<String,String>), and are stored using the Appear2mee class method, registerTags. The tags that have already been stored can be retrieved using the Appear2mee class method, tags; For example,
Note that tags dictionary is saved as a whole. To add a new tag, the original tags dictionary must be extended, then registered.
The SDK also allows the "pulling" of named messages from the 2mee Exchange. Currently only holocapsule messages (these are face videos) can be displayed in app. In order to retrieve a message the Appear2mee getMessage: method is used. A callback is called when the message is ready to display or has failed. If the message item is not null it can then be displayed.
The displayMessage method uses the same callbacks method for "accept" and "dismiss" as notifications. It allows for adding some extra user data so that the ResponseListener can be tailored to the message. In your Application class the appear2meeResponseListener can read the userData which is added to the Bundle.
The 2mee Exchange can send notifications based on the users last recorded location. In order to send the device location to the exchange some setup is required, if this is not done no location data is sent.
In order to start sending location information the SDK must have permission. In Android permissions can only be generated in an Activity so the call to start collection locations must be done in an Activity. Normally that would be done in your main activity and in the onCreate function using the Appear2mee.startLocationService method.