Android

This page explains how to configure push notifications for Android devices. Push notifications are a simple and effective way to increase engagement and communicate with your customers.

1. Register Vessel Push Service

To receive push notifications from Vessel, you need to add the Vessel Service and broadcast receivers in AndroidManifest.xml file before the closing tag:

<receiver
	android:name="com.vessel.VesselBroadcastReceiver"
  android:permission="com.google.android.c2dm.permission.SEND" >
  	<intent-filter>
      <!-- Receives the actual messages. -->
     <action android:name="com.google.android.c2dm.intent.RECEIVE" />
     <!-- Register to enable push notification -->
     <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
     
      <!--- Replace ME with your own package name -->
      <category android:name="REPLACE_ME_WITH_YOUT_PACKAGE_NAME" />
   </intent-filter>
</receiver>

<!--Vessel service to handle push registration and notification ->
<service android:name="com.vessel.VesselIntentService" />

2. Configure Permissions

To receive a push notification, add the following permissions in AndroidManifest.xml file before the closing tag:

<!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
<!-- The targetSdkVersion is optional, but it's always a good practice
         to target higher versions. -->
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/>

<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!--
     Creates a custom permission so only this app can receive its messages.

NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
           where PACKAGE is the application's package name.
-->

<permission android:name="REPLACE_ME.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

<uses-permission android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE" />

<!-- This app has permission to register and receive data message. -->
<uses-permission
        android:name="REPLACE_ME.permission.RECEIVE" />

3. Initialize Vessel Push

After saving the configuration above, you will need to initialize Vessel Push Notification. Create or open your Application class and copy/paste the code below. You can get your sender ID from the Google Developer Portal.

VesselSDK sdk = VesselSDK.getInstance(getApplicationContext());
	sdk.initializeSDK("YOUR_APP_SECRET_KEY");
	
	// Enable push notification here.
  sdk.initializeVesselPush(SENDER_ID);

(if you don't have a SENDER_ID then enable Google Cloud Messaging Service by completing the steps detailed in this tutorial )