This guide is a quick start to adding the Phunware Messaging SDK to an Android app. Android Studio is the recommended development environment for building an app with the Phunware Messaging SDK.
Step 1- Add the Phunware Maven remote repository. Insert this block into
Step 2 - Add the Messaging SDK as a dependency in your app's
This will automatically import the required dependency for Phunware Core
Step 3 (Optional) - Add beacon support if you are using beacons
If you would like to take advantage of the Messaging SDK's beacon support, simply add the
With properly configured beacons in your environments, no other code changes are required to take advantage of beacon based messaging.
Step 4 - Add Access Key and Signature key to Portal
Navigate to portal and add your access key and signature key from the GCM setup to your application.
Gcm setup can be done here: https://developers.google.com/cloud-messaging/android/client
Under these steps we can ignore a few things because they are already taken care of for you
Step 5 - Add SenderId to App build.gradle
In order to verify that we are receiving GCM notifications from the correct sender you must modify the build.gradle of your app to overwrite the SDK's GCMSenderId resValue
Step 6 - Add Phunware keys for App Id, Access Key, Signature Key and Encryption Key to Manifest
The App Id, Access Key, Signature Key and Encryption Key are found on the MaaS portal.
Step 7 - Add Location and Storage permissions to Manifest
This allows you to utilize location-based messages and beacon messaging. Note that background location notifications currently cannot work with runtime permissions required for apps targeting Android SDK level 23 and higher, so your targetSdkVersion in your build.gradle file must be 22 or lower.
Step 8 - Configure the Messaging SDK with your environment.
You should only initialize the Messaging SDK once, after you initialize PwCoreSession. Once it's complete, you can access the Location, Message and Attribute managers directly.
Once initialization is complete, users will be automatically notified with your custom broadcast messages. If you have location and storage permissions they will also be able to receive messages for location events, like entering a retail store.
Step 9 - Designate an Activity to launch from notifications
Notifications can be customized by extending the
NotificationCustomizationService. The intent which launches your activity from a notification will have extras with message and promo information.
Step 10 - Show Messages
MessageManager you can easily show a list of available messages. Note that calls to the MessageManager are asynchronous, and may require loading data from the network.