SlideShare a Scribd company logo
1 of 16
®
IBM Software Group
© 2014 IBM Corporation
Using the IBM MobileFirst Platform Foundation (MFP) Xamarin SDK Push
Notifications
for Android
@ajaychebbi
IBM MobileFirst Platform Foundation
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 2
Push Notifications - the basics
Notifications come to your device via the Cloud
services hosted by the OS vendor

Google Cloud Messaging service (GCM)

Apple Push Notification service (APNS)

Windows Notification Service (WNS)
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 3
Push Notifications - the basics

You have to do a bunch of handshakes and registrations e.g. above is for
GCM

Eventually the notification message goes from “your Server”

There is also the maintenance of devices and users and un-installs etc.

Excellent info on how it works at Xamarin.com
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 4
Push Notifications – pre reqs

This is going to be a long process to understand – so hang in there

More info here http://developer.xamarin.com/guides/cross-
platform/application_fundamentals/notifications/android/remote_notificati
ons_in_android/

Setup the Google API project and get the senderID and key
– If you dont have it, get it at https://code.google.com/apis/console

Also make sure you have the “Google APIs” emulator image (a real
device works much faster)
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 5
Push Notifications – MFP setup

Copy
WorklightSampleworklightWorklightSampleappsandroidWorklightSamplepush.
png to Resourcesdrawable

A sample adapter is shipped with the component that will be used to manage the
server side message sending etc
– Copy the componentworklightAssetsPushAdapter sample to
WorklightSampleworklightWorklightSampleadapters
–Create a security test “MySecurityTest” in
XtestworklightXtestserverconfauthenticationConfig.xml under <securityTests>
<securityTests>
<mobileSecurityTest name="MySecurityTest">
<testUser realm="SampleAppRealm"/>
<testDeviceId provisioningType="none"/>
</mobileSecurityTest>
.
.
</securityTests>
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 6
Push Notifications – Worklight setup

Add the Google API Key and sender ID in
WorklightSampleworklightWorklightSampleappsandroidWorklightSam
pleapplication-descriptor.xml

Also add the securityTest as “MySecurityTest”
<nativeAndroidApp id="androidXtest" platformVersion="6.2.0.00.20140825-1637"
version="1.0" xmlns="http://www.worklight.com/native-android-descriptor"
securityTest="MySecurityTest">
<displayName>androidXtest</displayName>
<description>androidXtest</description>
<pushSender key="YOUR_GCM_KEY" senderId="YOUR_GCM_ID"/>
<publicSigningKey></publicSigningKey>
<packageName></packageName>
</nativeAndroidApp>

Add the GCMSenderID to assetswlclient.properties
#For Push Notifications,uncomment below line and assign value to it
GcmSenderId = YOUR_GCM_ID
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 7
Push Notifications – App
Android application requires the following three things:
•
Permissions - An Android application must be granted permission to use the internet
and to receive messages from Google Cloud Messaging.
•
BroadcastReceiver - A BroadcastReceiver must be configured to listen for the
Intents that the Google Services Framework will publish when a message is received
from Google Cloud Messaging.
•
IntentService - The BroadcastReceiver will not handle the Intents itself, instead it will
invoke an IntentService that will process the messages.
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 8
Push Notifications – App Configuration
Define Permissions in PropertiesAssemblyInfo.cs
// This will prevent other apps on the device from receiving GCM messages for this app
// It is crucial that the package name does not start with an uppercase letter - this is forbidden by Android.
[assembly: Permission(Name = "@PACKAGE_NAME@.permission.C2D_MESSAGE")]
[assembly: UsesPermission(Name = "@PACKAGE_NAME@.permission.C2D_MESSAGE")]
// Gives the app permission to register and receive messages.
[assembly: UsesPermission(Name = "com.google.android.c2dm.permission.RECEIVE")]
// This permission is necessary only for Android 4.0.3 and below.
[assembly: UsesPermission(Name = "android.permission.GET_ACCOUNTS")]
// Need to access the internet for GCM
[assembly: UsesPermission(Name = "android.permission.INTERNET")]
// Needed to keep the processor from sleeping when a message arrives
[assembly: UsesPermission(Name = "android.permission.WAKE_LOCK")]
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 9
Push Notifications – App Configuration
BroadcastReceiver and Intent
Define BroadcastReceiver and Intent Service in propertiesAndroidManifest.xml
Worklight provides a inbuilt broadcast receiver and Intent service – so just add them to the
manifest
<service android:name="com.worklight.wlclient.push.GCMIntentService" />
<receiver android:name="com.worklight.wlclient.push.WLBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="worklightsample.android" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="worklightsample.android" />
</intent-filter>
</receiver>
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 10
Push Notifications – App Configuration
Define a IntentFilter for a activity in the app
•
Make sure app_name in Strings.xml is WorklightSample.Android
•
Edit MainActivity.cs and add the following IntentFilter
[IntentFilter (new[]{" worklightsample.android.WorklightSample.Android.NOTIFICATION"} ,
Categories=new[]{Intent.CategoryDefault})]
Format: [package].[app_name from Strings.xml].NOTIFICATION
•Override the lifecycle methods of MainActivity.cs
protected override void OnResume ()
{
base.OnResume(); wlClient.PushService.Foreground = true;
}
protected override void OnPause ()
{
base.OnPause(); wlClient.PushService.Foreground = false;
}
protected override void OnDestroy ()
{
base.OnDestroy(); wlClient.PushService.UnregisterReceivers ();
}
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 11
Push Notifications – lets send a message

Execute the adapter to send a message
C:devworkspacesXtestworklightXtest>mfp invoke
[?] Which adapter do you want to use? PushAdapter
[?] Enter the comma-separated parameters: "worklight","Hello!"
Eventually you will use APIs in the adapter to send notifications from your
server side application
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 12
Push Notifications – the Notification!
If app is in foreground – the Android
activity gets the
notification
If the app is in the background – you see
the notification on the notification bar
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 13
Push Notifications – API

The first step is to create an instance of the WLClient class:
IworklightClient wlClient = Worklight.Xamarin.Android.WorklightClient.CreateInstance (this);
WorklightPushService pushService = wlClient.PushService;

You do all push notification operations from the WorklightPushService
ReadyToSubscribe Event – When connecting to a Worklight Server, the app
attempts to register itself with the GCM server to receive push
notifications. Called when the registration is complete.
InitRegistration() - To initiate the registration sequence.
client.PushService.ReadyToSubscribe += HandleReadyToSubscribe;
client.PushService.InitRegistration();
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 14
Push Notifications – API
Use the RegisterEventSourceNotificationCallback method to register an alias
on a particular event source.
void HandleReadyToSubscribe(object sender, EventArgs a)
{
Console.WriteLine ("We are ready to subscribe to the notification service!!");
client.PushService.RegisterEventSourceNotificationCallback
(pushAlias,"PushAdapter","PushEventSource",new NotificationListener ());
client.PushService.SubscribeToEventSource(pushAlias,new Dictionary<string,string>());
}
IBM Software Group | Cloud - MobileFirst
Innovation for a smarter planet 15
Push Notifications – API
Listener gets the notifications
public class NotificationListener:WorklightPushNotificationListener
{
public void OnMessage(JsonObject NotificationProperties, JsonObject Payload)
{
Console.WriteLine ("Got notification!");
Console.WriteLine (NotificationProperties.ToString ());
}
}
IBM Software Group | Cloud - MobileFirst

More Related Content

Viewers also liked

Ibm mobile first strategy software approach
Ibm mobile first strategy software approachIbm mobile first strategy software approach
Ibm mobile first strategy software approachbupbechanhgmail
 
Presentacion módulo inserción laboral instalador energia r enovable
Presentacion módulo inserción laboral  instalador energia r enovablePresentacion módulo inserción laboral  instalador energia r enovable
Presentacion módulo inserción laboral instalador energia r enovableMarta Fernandez-Portillo
 
Summary worksheet phonics and phonological awareness
Summary worksheet phonics and phonological awarenessSummary worksheet phonics and phonological awareness
Summary worksheet phonics and phonological awarenessadriana palomo
 
Boletín Informativo PSOE de Villarrobledo, mayo2015
Boletín Informativo PSOE de Villarrobledo,  mayo2015Boletín Informativo PSOE de Villarrobledo,  mayo2015
Boletín Informativo PSOE de Villarrobledo, mayo2015Libre Pensador
 
Publicidade na Web? Saiba como comprar.
Publicidade na Web? Saiba como comprar.Publicidade na Web? Saiba como comprar.
Publicidade na Web? Saiba como comprar.Tayro Mendonça
 
Nyílt levél az országgyűlési képviselőknek
Nyílt levél az országgyűlési képviselőknekNyílt levél az országgyűlési képviselőknek
Nyílt levél az országgyűlési képviselőknekmuveszpeticio
 
Métodos de encriptación en las redes privadas virtuales
Métodos de encriptación en las redes privadas virtualesMétodos de encriptación en las redes privadas virtuales
Métodos de encriptación en las redes privadas virtualesESPE
 
MARCO LEGAL DE LA INSPECCIÓN DE SERVICIOS SANITARIOS
MARCO LEGAL DE LA INSPECCIÓN DE SERVICIOS SANITARIOSMARCO LEGAL DE LA INSPECCIÓN DE SERVICIOS SANITARIOS
MARCO LEGAL DE LA INSPECCIÓN DE SERVICIOS SANITARIOSMiguel Angel García Alonso
 
CUARTA UNIDAD DE LAS TICS EN LA EDUCACION
CUARTA UNIDAD DE LAS TICS EN LA EDUCACIONCUARTA UNIDAD DE LAS TICS EN LA EDUCACION
CUARTA UNIDAD DE LAS TICS EN LA EDUCACIONWendy Rdz
 
Oracle PeopleSoft applications are under attack (HITB AMS)
Oracle PeopleSoft applications are under attack (HITB AMS)Oracle PeopleSoft applications are under attack (HITB AMS)
Oracle PeopleSoft applications are under attack (HITB AMS)ERPScan
 
Evidencia cientifica en depresion bipolar
Evidencia cientifica en depresion bipolarEvidencia cientifica en depresion bipolar
Evidencia cientifica en depresion bipolarvitriolum
 

Viewers also liked (20)

Ibm mobile first strategy software approach
Ibm mobile first strategy software approachIbm mobile first strategy software approach
Ibm mobile first strategy software approach
 
Presentacion módulo inserción laboral instalador energia r enovable
Presentacion módulo inserción laboral  instalador energia r enovablePresentacion módulo inserción laboral  instalador energia r enovable
Presentacion módulo inserción laboral instalador energia r enovable
 
Summary worksheet phonics and phonological awareness
Summary worksheet phonics and phonological awarenessSummary worksheet phonics and phonological awareness
Summary worksheet phonics and phonological awareness
 
VII Foro Audiovisual
VII Foro AudiovisualVII Foro Audiovisual
VII Foro Audiovisual
 
Boletín Informativo PSOE de Villarrobledo, mayo2015
Boletín Informativo PSOE de Villarrobledo,  mayo2015Boletín Informativo PSOE de Villarrobledo,  mayo2015
Boletín Informativo PSOE de Villarrobledo, mayo2015
 
Pitch outline
Pitch outlinePitch outline
Pitch outline
 
Publicidade na Web? Saiba como comprar.
Publicidade na Web? Saiba como comprar.Publicidade na Web? Saiba como comprar.
Publicidade na Web? Saiba como comprar.
 
Nyílt levél az országgyűlési képviselőknek
Nyílt levél az országgyűlési képviselőknekNyílt levél az országgyűlési képviselőknek
Nyílt levél az országgyűlési képviselőknek
 
Project architect job description
Project architect job descriptionProject architect job description
Project architect job description
 
Escuela inglesa de ballet
Escuela inglesa de balletEscuela inglesa de ballet
Escuela inglesa de ballet
 
08 rugosidad
08 rugosidad08 rugosidad
08 rugosidad
 
02 kalewska
02 kalewska02 kalewska
02 kalewska
 
Métodos de encriptación en las redes privadas virtuales
Métodos de encriptación en las redes privadas virtualesMétodos de encriptación en las redes privadas virtuales
Métodos de encriptación en las redes privadas virtuales
 
MARCO LEGAL DE LA INSPECCIÓN DE SERVICIOS SANITARIOS
MARCO LEGAL DE LA INSPECCIÓN DE SERVICIOS SANITARIOSMARCO LEGAL DE LA INSPECCIÓN DE SERVICIOS SANITARIOS
MARCO LEGAL DE LA INSPECCIÓN DE SERVICIOS SANITARIOS
 
CUARTA UNIDAD DE LAS TICS EN LA EDUCACION
CUARTA UNIDAD DE LAS TICS EN LA EDUCACIONCUARTA UNIDAD DE LAS TICS EN LA EDUCACION
CUARTA UNIDAD DE LAS TICS EN LA EDUCACION
 
Relé de 8 patillas
Relé de 8 patillasRelé de 8 patillas
Relé de 8 patillas
 
Oracle PeopleSoft applications are under attack (HITB AMS)
Oracle PeopleSoft applications are under attack (HITB AMS)Oracle PeopleSoft applications are under attack (HITB AMS)
Oracle PeopleSoft applications are under attack (HITB AMS)
 
CNS-CP Certification
CNS-CP CertificationCNS-CP Certification
CNS-CP Certification
 
CV Gabriel Luna
CV Gabriel LunaCV Gabriel Luna
CV Gabriel Luna
 
Evidencia cientifica en depresion bipolar
Evidencia cientifica en depresion bipolarEvidencia cientifica en depresion bipolar
Evidencia cientifica en depresion bipolar
 

Similar to Push Notification in IBM MobileFirst Xamarin SDK

Android broadcast receiver tutorial
Android broadcast receiver   tutorialAndroid broadcast receiver   tutorial
Android broadcast receiver tutorialmaamir farooq
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorialmaamir farooq
 
Connecting Xamarin Apps with IBM Worklight in Bluemix
Connecting Xamarin Apps with IBM Worklight in BluemixConnecting Xamarin Apps with IBM Worklight in Bluemix
Connecting Xamarin Apps with IBM Worklight in BluemixIBM
 
Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...naseeb20
 
Urban Airship and Android Integration for Push Notification and In-App Notifi...
Urban Airship and Android Integration for Push Notification and In-App Notifi...Urban Airship and Android Integration for Push Notification and In-App Notifi...
Urban Airship and Android Integration for Push Notification and In-App Notifi...Zeeshan Rahman
 
Urban Airship & Android Application Integration Document
Urban Airship & Android Application Integration DocumentUrban Airship & Android Application Integration Document
Urban Airship & Android Application Integration Documentmobi fly
 
Extending An Android App Using the IBM Push for Bluemix Cloud Service
Extending An Android App Using the IBM Push for Bluemix Cloud ServiceExtending An Android App Using the IBM Push for Bluemix Cloud Service
Extending An Android App Using the IBM Push for Bluemix Cloud ServiceIBM developerWorks
 
Cloud Foundry a Developer's Perspective
Cloud Foundry a Developer's PerspectiveCloud Foundry a Developer's Perspective
Cloud Foundry a Developer's PerspectiveDave McCrory
 
Android Cloud to Device Messaging Framework at GTUG Stockholm
Android Cloud to Device Messaging Framework at GTUG StockholmAndroid Cloud to Device Messaging Framework at GTUG Stockholm
Android Cloud to Device Messaging Framework at GTUG StockholmJohan Nilsson
 
Android Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App EngineAndroid Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App EngineLars Vogel
 
Develop for Windows 10 (Preview)
Develop for Windows 10 (Preview)Develop for Windows 10 (Preview)
Develop for Windows 10 (Preview)Dan Ardelean
 
2015 dan ardelean develop for windows 10
2015 dan ardelean   develop for windows 10 2015 dan ardelean   develop for windows 10
2015 dan ardelean develop for windows 10 Codecamp Romania
 
Skinning Android for Embedded Applications
Skinning Android for Embedded ApplicationsSkinning Android for Embedded Applications
Skinning Android for Embedded ApplicationsVIA Embedded
 
FOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingFOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingJohan Nilsson
 
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...Will it run or will it not run? Background processes in Android 6 - Anna Lifs...
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...DroidConTLV
 
Cloud Management With System Center Application Controller ver1
Cloud Management With System Center Application Controller ver1Cloud Management With System Center Application Controller ver1
Cloud Management With System Center Application Controller ver1Lai Yoong Seng
 
Web Push Notifications
Web Push NotificationsWeb Push Notifications
Web Push NotificationsUgur Eker
 
Android Cloud To Device Messaging
Android Cloud To Device MessagingAndroid Cloud To Device Messaging
Android Cloud To Device MessagingFernando Cejas
 
Android cloud to device messaging
Android cloud to device messagingAndroid cloud to device messaging
Android cloud to device messagingFe
 

Similar to Push Notification in IBM MobileFirst Xamarin SDK (20)

Android broadcast receiver tutorial
Android broadcast receiver   tutorialAndroid broadcast receiver   tutorial
Android broadcast receiver tutorial
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorial
 
Connecting Xamarin Apps with IBM Worklight in Bluemix
Connecting Xamarin Apps with IBM Worklight in BluemixConnecting Xamarin Apps with IBM Worklight in Bluemix
Connecting Xamarin Apps with IBM Worklight in Bluemix
 
Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...
 
Urban Airship and Android Integration for Push Notification and In-App Notifi...
Urban Airship and Android Integration for Push Notification and In-App Notifi...Urban Airship and Android Integration for Push Notification and In-App Notifi...
Urban Airship and Android Integration for Push Notification and In-App Notifi...
 
Urban Airship & Android Application Integration Document
Urban Airship & Android Application Integration DocumentUrban Airship & Android Application Integration Document
Urban Airship & Android Application Integration Document
 
Extending An Android App Using the IBM Push for Bluemix Cloud Service
Extending An Android App Using the IBM Push for Bluemix Cloud ServiceExtending An Android App Using the IBM Push for Bluemix Cloud Service
Extending An Android App Using the IBM Push for Bluemix Cloud Service
 
Android Froyo
Android FroyoAndroid Froyo
Android Froyo
 
Cloud Foundry a Developer's Perspective
Cloud Foundry a Developer's PerspectiveCloud Foundry a Developer's Perspective
Cloud Foundry a Developer's Perspective
 
Android Cloud to Device Messaging Framework at GTUG Stockholm
Android Cloud to Device Messaging Framework at GTUG StockholmAndroid Cloud to Device Messaging Framework at GTUG Stockholm
Android Cloud to Device Messaging Framework at GTUG Stockholm
 
Android Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App EngineAndroid Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App Engine
 
Develop for Windows 10 (Preview)
Develop for Windows 10 (Preview)Develop for Windows 10 (Preview)
Develop for Windows 10 (Preview)
 
2015 dan ardelean develop for windows 10
2015 dan ardelean   develop for windows 10 2015 dan ardelean   develop for windows 10
2015 dan ardelean develop for windows 10
 
Skinning Android for Embedded Applications
Skinning Android for Embedded ApplicationsSkinning Android for Embedded Applications
Skinning Android for Embedded Applications
 
FOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingFOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device Messaging
 
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...Will it run or will it not run? Background processes in Android 6 - Anna Lifs...
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...
 
Cloud Management With System Center Application Controller ver1
Cloud Management With System Center Application Controller ver1Cloud Management With System Center Application Controller ver1
Cloud Management With System Center Application Controller ver1
 
Web Push Notifications
Web Push NotificationsWeb Push Notifications
Web Push Notifications
 
Android Cloud To Device Messaging
Android Cloud To Device MessagingAndroid Cloud To Device Messaging
Android Cloud To Device Messaging
 
Android cloud to device messaging
Android cloud to device messagingAndroid cloud to device messaging
Android cloud to device messaging
 

Recently uploaded

9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 

Recently uploaded (7)

9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 

Push Notification in IBM MobileFirst Xamarin SDK

  • 1. ® IBM Software Group © 2014 IBM Corporation Using the IBM MobileFirst Platform Foundation (MFP) Xamarin SDK Push Notifications for Android @ajaychebbi IBM MobileFirst Platform Foundation
  • 2. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 2 Push Notifications - the basics Notifications come to your device via the Cloud services hosted by the OS vendor  Google Cloud Messaging service (GCM)  Apple Push Notification service (APNS)  Windows Notification Service (WNS)
  • 3. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 3 Push Notifications - the basics  You have to do a bunch of handshakes and registrations e.g. above is for GCM  Eventually the notification message goes from “your Server”  There is also the maintenance of devices and users and un-installs etc.  Excellent info on how it works at Xamarin.com
  • 4. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 4 Push Notifications – pre reqs  This is going to be a long process to understand – so hang in there  More info here http://developer.xamarin.com/guides/cross- platform/application_fundamentals/notifications/android/remote_notificati ons_in_android/  Setup the Google API project and get the senderID and key – If you dont have it, get it at https://code.google.com/apis/console  Also make sure you have the “Google APIs” emulator image (a real device works much faster)
  • 5. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 5 Push Notifications – MFP setup  Copy WorklightSampleworklightWorklightSampleappsandroidWorklightSamplepush. png to Resourcesdrawable  A sample adapter is shipped with the component that will be used to manage the server side message sending etc – Copy the componentworklightAssetsPushAdapter sample to WorklightSampleworklightWorklightSampleadapters –Create a security test “MySecurityTest” in XtestworklightXtestserverconfauthenticationConfig.xml under <securityTests> <securityTests> <mobileSecurityTest name="MySecurityTest"> <testUser realm="SampleAppRealm"/> <testDeviceId provisioningType="none"/> </mobileSecurityTest> . . </securityTests>
  • 6. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 6 Push Notifications – Worklight setup  Add the Google API Key and sender ID in WorklightSampleworklightWorklightSampleappsandroidWorklightSam pleapplication-descriptor.xml  Also add the securityTest as “MySecurityTest” <nativeAndroidApp id="androidXtest" platformVersion="6.2.0.00.20140825-1637" version="1.0" xmlns="http://www.worklight.com/native-android-descriptor" securityTest="MySecurityTest"> <displayName>androidXtest</displayName> <description>androidXtest</description> <pushSender key="YOUR_GCM_KEY" senderId="YOUR_GCM_ID"/> <publicSigningKey></publicSigningKey> <packageName></packageName> </nativeAndroidApp>  Add the GCMSenderID to assetswlclient.properties #For Push Notifications,uncomment below line and assign value to it GcmSenderId = YOUR_GCM_ID
  • 7. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 7 Push Notifications – App Android application requires the following three things: • Permissions - An Android application must be granted permission to use the internet and to receive messages from Google Cloud Messaging. • BroadcastReceiver - A BroadcastReceiver must be configured to listen for the Intents that the Google Services Framework will publish when a message is received from Google Cloud Messaging. • IntentService - The BroadcastReceiver will not handle the Intents itself, instead it will invoke an IntentService that will process the messages.
  • 8. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 8 Push Notifications – App Configuration Define Permissions in PropertiesAssemblyInfo.cs // This will prevent other apps on the device from receiving GCM messages for this app // It is crucial that the package name does not start with an uppercase letter - this is forbidden by Android. [assembly: Permission(Name = "@PACKAGE_NAME@.permission.C2D_MESSAGE")] [assembly: UsesPermission(Name = "@PACKAGE_NAME@.permission.C2D_MESSAGE")] // Gives the app permission to register and receive messages. [assembly: UsesPermission(Name = "com.google.android.c2dm.permission.RECEIVE")] // This permission is necessary only for Android 4.0.3 and below. [assembly: UsesPermission(Name = "android.permission.GET_ACCOUNTS")] // Need to access the internet for GCM [assembly: UsesPermission(Name = "android.permission.INTERNET")] // Needed to keep the processor from sleeping when a message arrives [assembly: UsesPermission(Name = "android.permission.WAKE_LOCK")]
  • 9. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 9 Push Notifications – App Configuration BroadcastReceiver and Intent Define BroadcastReceiver and Intent Service in propertiesAndroidManifest.xml Worklight provides a inbuilt broadcast receiver and Intent service – so just add them to the manifest <service android:name="com.worklight.wlclient.push.GCMIntentService" /> <receiver android:name="com.worklight.wlclient.push.WLBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="worklightsample.android" /> </intent-filter> <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="worklightsample.android" /> </intent-filter> </receiver>
  • 10. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 10 Push Notifications – App Configuration Define a IntentFilter for a activity in the app • Make sure app_name in Strings.xml is WorklightSample.Android • Edit MainActivity.cs and add the following IntentFilter [IntentFilter (new[]{" worklightsample.android.WorklightSample.Android.NOTIFICATION"} , Categories=new[]{Intent.CategoryDefault})] Format: [package].[app_name from Strings.xml].NOTIFICATION •Override the lifecycle methods of MainActivity.cs protected override void OnResume () { base.OnResume(); wlClient.PushService.Foreground = true; } protected override void OnPause () { base.OnPause(); wlClient.PushService.Foreground = false; } protected override void OnDestroy () { base.OnDestroy(); wlClient.PushService.UnregisterReceivers (); }
  • 11. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 11 Push Notifications – lets send a message  Execute the adapter to send a message C:devworkspacesXtestworklightXtest>mfp invoke [?] Which adapter do you want to use? PushAdapter [?] Enter the comma-separated parameters: "worklight","Hello!" Eventually you will use APIs in the adapter to send notifications from your server side application
  • 12. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 12 Push Notifications – the Notification! If app is in foreground – the Android activity gets the notification If the app is in the background – you see the notification on the notification bar
  • 13. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 13 Push Notifications – API  The first step is to create an instance of the WLClient class: IworklightClient wlClient = Worklight.Xamarin.Android.WorklightClient.CreateInstance (this); WorklightPushService pushService = wlClient.PushService;  You do all push notification operations from the WorklightPushService ReadyToSubscribe Event – When connecting to a Worklight Server, the app attempts to register itself with the GCM server to receive push notifications. Called when the registration is complete. InitRegistration() - To initiate the registration sequence. client.PushService.ReadyToSubscribe += HandleReadyToSubscribe; client.PushService.InitRegistration();
  • 14. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 14 Push Notifications – API Use the RegisterEventSourceNotificationCallback method to register an alias on a particular event source. void HandleReadyToSubscribe(object sender, EventArgs a) { Console.WriteLine ("We are ready to subscribe to the notification service!!"); client.PushService.RegisterEventSourceNotificationCallback (pushAlias,"PushAdapter","PushEventSource",new NotificationListener ()); client.PushService.SubscribeToEventSource(pushAlias,new Dictionary<string,string>()); }
  • 15. IBM Software Group | Cloud - MobileFirst Innovation for a smarter planet 15 Push Notifications – API Listener gets the notifications public class NotificationListener:WorklightPushNotificationListener { public void OnMessage(JsonObject NotificationProperties, JsonObject Payload) { Console.WriteLine ("Got notification!"); Console.WriteLine (NotificationProperties.ToString ()); } }
  • 16. IBM Software Group | Cloud - MobileFirst