Overview

Skill Level: Intermediate

Manually integrating the Cordova plug-in for Android app development.

Prerequisites

You can manually integrate the Cordova plug-in.

Step-by-step

  1. Add library dependencies

    1. Add the Google Play service library and appsupport v4 library dependencies to your project.
    2. Add the MCE SDK library (ibm-mobile-push-android-sdk-<version number>.jar) as an Android library to the project.
    3. Add the MCE Cordova plug-in libraries (ibm-mobile-push-android-sdk-js-<version number>.jar and ibm-mobile-push-android-plugin-cordova-<version number>.jar) as Android libraries to the project.
  2. Add the plugins

    1. Add the Cordova plug-in to config.xml under the “widget” nodel:
      <feature name="MCEPlugin">
      <param name="android-package" value="com.ibm.mce.plugin.cordova.MceCordovaPlugin" />
      </feature>
    2. Add MCEPlugin.js to the project.
  3. Add the following to strings.xml.

    $ANDROID_APPKEY is your app key and $SENDER_ID is your GCM project ID.

    <string name="appkey">$ANDROID_APPKEY</string>
    <string name="senderid">$SENDER_ID</string>
  4. Modify the AndroidManifest.xml

    In AndroidManifest.xml, make the following modifications. $PACKAGE_NAME is your application package name, $CUSTOM_ACTIONS is the type of the custom notification actions you want to register in the JavaScript code that is separated by space, and $SERVER_URL is the MCE server URL.

    For the $SERVER_URL for your pod, go here. 

    1. Add permissions
      <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
      <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
      <permission android:name="$PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
      <uses-permission android:name="$PACKAGE_NAME.permission.C2D_MESSAGE"/>
      <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
      <uses-permission android:name="android.permission.WAKE_LOCK"/>
      <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
      <uses-permission android:name="android.permission.USE_CREDENTIALS"/>
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    2. Add metadata under application node
      <!-- MCE properties -->
      <meta-data
      android:name="messagingService"
      android:value="gcm" />
      <meta-data
      android:name="mceAppKey"
      android:value="@string/appkey" />
      <meta-data
      android:name="mceSenderId"
      android:value="@string/senderid" />
      <meta-data
      android:name="mceSessionEnabled"
      android:value="true" />
      <meta-data
      android:name="mceSessionDuration"
      android:value="5" />
      <meta-data
      android:name="customActions"
      android:value="$CUSTOM_ACTIONS" />
      <!--
      MCE server definition:
      "us" - American server
      "eu" - EU server
      The value can also be a custom url like "https://myserver.api.mce.com"
      If not defined, the default value is "us"
      -->
      <meta-data
      android:name="mceServer"
      android:value="$SERVER_URL" />
      <meta-data android:name="com.google.android.gms.version"
      android:value="@integer/google_play_services_version"  
    3. Add receivers
      <receiver android:name="com.ibm.mce.sdk.js.JsonMceBroadcastReceiver">
      <intent-filter>
      <action android:name="com.ibm.mce.sdk.NOTIFIER" />
      </intent-filter>
      </receiver>
      <receiver android:name="com.ibm.mce.sdk.wi.AlarmReceiver" >
      <intent-filter>
      <action android:name="android.intent.action.BOOT_COMPLETED" />
      </intent-filter>
      <intent-filter>
      <action android:name="android.intent.action.TIMEZONE_CHANGED" />
      </intent-filter>
      <intent-filter>
      <action android:name="android.intent.action.PACKAGE_REPLACED" />
      <data android:scheme="package" />
      </intent-filter>
      <intent-filter>
      <action android:name="android.intent.action.LOCALE_CHANGED" />
      </intent-filter>
      </receiver>
      <receiver android:name="com.ibm.mce.sdk.notification.NotifActionReceiver">

    4. Add providers
       <provider
      android:name="com.ibm.mce.sdk.db.Provider"
      android:authorities="$PACKAGE_NAME.MCE_PROVIDER"
      android:exported="false" />
      <provider
      android:name="com.ibm.mce.sdk.js.Provider"
      android:authorities="$PACKAGE_NAME.MCE_JSON_PROVIDER"
      android:exported="false" />
    5. Add services
      /><service android:name=”com.ibm.mce.sdk.events.EventsAlarmListener” />
      <service android:name=”com.ibm.mce.sdk.registration.RegistrationIntentService” />
      <service android:name=”com.ibm.mce.sdk.attributes.AttributesQueueConsumer” />
      <service android:name=”com.ibm.mce.sdk.session.SessionTrackingIntentService” />
      <service android:name=”com.ibm.mce.sdk.registration.PhoneHomeIntentService” />

    6. Set the application node android:name attribute value to com.ibm.mce.sdk.js.MceJsonApplication.
    7. Add these permissions for GCM:

      <!– C2D_MESSAGE is required for receiving GCM messages –>
      <permission
      android:name=”$PACKAGE_NAME.permission.C2D_MESSAGE”
      android:protectionLevel=”signature” />

      <!– C2D_MESSAGE is required for receiving GCM messages –>
      <uses-permission android:name=”$PACKAGE_NAME.permission.C2D_MESSAGE” />

      <!– c2dm.permission.RECEIVE is required for receiving GCM messages –>
      <uses-permission android:name=”com.google.android.c2dm.permission.RECEIVE” />

      Add these under the <application> node:

      <!– MCE properties –>
      <meta-data android:name=”messagingService” android:value=”gcm” />
      <meta-data android:name=”mceSenderId” android:value=”@string/senderid” />

      <receiver android:name=”com.google.android.gms.gcm.GcmReceiver” android:priority=”999″>
      <intent-filter android:permission=”com.google.android.c2dm.permission.SEND” >
      <action android:name=”com.google.android.c2dm.intent.RECEIVE” />
      <category android:name=”$PACKAGE_NAME” />
      </intent-filter>
      <intent-filter android:permission=”com.google.android.c2dm.permission.SEND” android:priority=”999″>
      <action android:name=”com.google.android.c2dm.intent.REGISTRATION” />
      <category android:name=”$PACKAGE_NAME” />
      </intent-filter>
      </receiver>

      <!– MceGcmListenerService is required for GCM handling –>
      <service android:name=”com.ibm.mce.sdk.gcm.MceGcmListenerService” android:exported=”false” >
      <intent-filter>
      <action android:name=”com.google.android.c2dm.intent.RECEIVE” />
      </intent-filter>
      </service>

      Add this to the res/values/strings.xml file
      <string name=”senderid”>$SENDER_ID</string>

    8. Add these permissions for FCM:

      <!– C2D_MESSAGE is required for receiving GCM messages –>
      <permission
      android:name=”$PACKAGE_NAME.permission.C2D_MESSAGE”
      android:protectionLevel=”signature” />

      <!– C2D_MESSAGE is required for receiving GCM messages –>
      <uses-permission android:name=”$PACKAGE_NAME.permission.C2D_MESSAGE” />

      <!– c2dm.permission.RECEIVE is required for receiving GCM messages –>
      <uses-permission android:name=”com.google.android.c2dm.permission.RECEIVE” />

       
      Add these lines to the <application> node:

      <!– MCE properties –>
      <meta-data android:name=”messagingService” android:value=”fcm” />
      <meta-data android:name=”mceSenderId” android:value=”” />

      <!– FCM Registration –>
      <service
      android:name=”com.ibm.mce.sdk.fcm.FcmInstanceIdService”>
      <intent-filter>
      <action android:name=”com.google.firebase.INSTANCE_ID_EVENT”/>
      </intent-filter>
      </service>

      <!– FCM Messages –>
      <service
      android:name=”com.ibm.mce.sdk.fcm.FcmMessagingService”>
      <intent-filter>
      <action android:name=”com.google.firebase.MESSAGING_EVENT”/>
      </intent-filter>
      </service>

      Add this line to the res/values/strings.xml:
      <string name=”senderid”></string>

Expected outcome

For more information, see the documentation.

Go Back to the Mobile App Messaging home page.

Join The Discussion

Your email address will not be published. Required fields are marked *