Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

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 allprojects -> repositories:

allprojects {
    repositories {
        maven {
	    	credentials {
    	    	username 'username'
      	        password 'password'
           	}
           	url "https://nexus.phunware.com/content/groups/phunware-messaging/"
       	}
    }
}

Be sure to replace username and password with the your credentials.

Step 2 - Add the Mapping SDK as a dependency in your app's build.gradle file:

apply plugin: 'com.android.application'

android {
	...
}

dependencies {
	...
    compile 'com.phunware.messaging:messaging:3.0.0'
    ...
}

 

Step 3 (Optional) - Add beacon support if you are using beacons

dependencies {
  ...
  compile 'com.phunware.messaging:messaging:3.0.0'
  compile 'com.phunware.messaging:beacon-location-manager:3.0.0'
  ...
}

If you would like to take advantage of the Messaging SDK's beacon support, simply add the beacon-location-manager dependency.

With properly configured beacons in your environments, no other code changes are required to take advantage of beacon based messaging.

Step 4 - Add Phunware keys for App Id, Access Key, Signature Key and Encryption Key

<meta-data android:name="com.phunware.APPLICATION_ID" android:value="@string/app_id" />
<meta-data android:name="com.phunware.ACCESS_KEY" android:value="@string/access_key" />
<meta-data android:name="com.phunware.SIGNATURE_KEY" android:value="@string/signature_key" />
<meta-data android:name="com.phunware.ENCRYPTION_KEY" android:value="@string/encrypt_key" />

The App Id, Access Key, Signature Key and Encryption Key are found on the MaaS portal.

Step 5 - Configure the Messaging SDK with your environment.

public class MainActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 
    if (savedInstanceState == null) {
      new LocationMessaging.Builder(this)
          .orgId(123L)
          .appId(456L)
          .environment(LocationMessaging.Environment.PROD)
          .build();
    }
  }

} 

You should only initialize the Messaging SDK once.  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 messages for location events, like entering a retail store.

Step 6 - Show Messages

public class MessageListFragment extends Fragment {
 
  @Override
  public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    LocationMessaging.messageManager().getMessages(new Callback<List<Message>>() {
      @Override
      public void onSuccess(List<Message> data) {
        myMessageListAdapter.addAll(data);
      }

      @Override
      public void onFailed(Throwable e) {
        onError(e);
      }
    });
  }


}

Using the 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.

  • No labels