Sie sind auf Seite 1von 3

Guide for Implementing GCM Push Using SMP Cloud Platform

Includes code snippets for getting GCM Registration Id and receiving Push Notifi
cations
Author: Sirisha Pabbiti
Guide for Implementing GCM Push Using SMP Cloud Platform
2
TABLE OF CONTENTS
INTRODUCTION ...................................................................
............................................................................ 3
PREREQUISITES ..................................................................
............................................................................ 3
STEPS ..........................................................................
................................................................................
..... 3
1. SMP: ENABLING THE APPLICATION FOR GCM PUSH ..................................
............................. 3
2. CLIENT SIDE IMPLEMENTATION ..................................................
................................................. 4
<USES-PERMISSION ANDROID:NAME="ANDROID.PERMISSION.INTERNET" /> .................
.............................. 4
FURTHER INFORMATION ............................................................
................................................................... 5
REFERENCES .....................................................................
............................................................................. 5
Guide for Implementing GCM Push Using SMP Cloud Platform
3
INTRODUCTION
SAP Mobile Platform (SMP), enterprise edition, cloud version can be used to buil
d lightweight, on-demand applications. The platform offers authentication, secur
e on-boarding, native push notifications and reporting capabilities for enterpri
se mobile applications.
This document will guide you on how to configure and receive GCM (native android
push) push via SMP server.
PREREQUISITES
? A SAP HANA Cloud account subscribed SAP Mobile Platform application. For more
information on how to obtain a HANA account with SMP, refer the below link.
(https://help.hana.ondemand.com/mobile/frameset.htm?doc/html/mdw1361529553461.ht
ml)
? An Application created in SMP Administration portal.
? Android application to register with SMP cloud.
? Project ID and API key from Google console, refer the below link to get projec
t Id and API key.
(http://developer.android.com/guide/google/gcm/gs.html)
STEPS
1. SMP: ENABLING THE APPLICATION FOR GCM PUSH
Select the Application for which GCM notification service should be enabled from
Applications tab. Now go to PUSH tab inside the application and give API Key an
d Project ID (Sender ID) and save the application.
Now the application is enabled for GCM push Notifications.
This configuration is one time process done by the Administrator, Clients using
this application can get the settings to their device and use them in further pr
ocess of registration.
Guide for Implementing GCM Push Using SMP Cloud Platform
4
2. CLIENT SIDE IMPLEMENTATION
2.1 The Android Manifest.xml should be modified with the following tags.
Manifest.xml
The application will need particular manifest elements in order to participate i
n GCM. The following section should be added to the AndroidManifest.xml, with th
e package name of the application substituted for the com.example.gcmdemo string b
elow. This section registers the GCMReceiver broadcast receiver. Note that these
tags must be within the <application> section of the manifest.
<! -- Only GCM servers can send messages for the app. If permission is not set -
any other app can generate it -->
<receiver android:name=" com.sybase.mo.GCMReceiver" android:permission="com.goog
le.android.c2dm.permission.SEND">
<! -- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.sybase.myapp" />
</intent-filter>
<! -- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.sybase.myapp />
</intent-filter>
</receiver>
The following permissions are also needed in the manifest, again with the packag
e name of the application substituted for the com.example.gcmdemo string below.
<! -- Only this application can receive the messages and registration result -->
<permission android:name="com.sybase.myapp.permission.C2D_MESSAGE" android:prote
ctionLevel="signature" />
<uses-permission android: name="com.sybase.myapp.permission.C2D_MESSAGE" />
<! -- This app has permission to register and receive message -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<! -- Send the registration id to the server -->
<uses-permission android:name="android.permission.INTERNET" />
2.2 Code Snippet to get GCM Registration ID from Google console.
Before getting the GCM registration ID, the client should have registered to the
application created in SMP cloud, which was enabled for GCM push services and h
e can get the GCM sender ID from the settings for his registered user.
Following is the code to get GCM Registration ID.
Guide for Implementing GCM Push Using SMP Cloud Platform
5
//These are inbuilt APIs given by Google
GCMRegistrar.checkDevice(this.mContext); // context of the class or application
GCMRegistrar.checkManifest(this.mContext);
final String regId = GCMRegistrar.getRegistrationId(this.mContext);
if (regId.equals("")) {
GCMRegistrar.register(this.mContext, "GCM Sender ID");// Sender ID or project ID
obtained from Google concole
} else {
Log.v("GCM", "Already registered");
}
After obtaining the GCM Registration ID (specific to your device), we need to up
date this to the registered user in SMP cloud so as to receive any notification
from SMP to your device. This can be done by HTTP PUT operation on the registere
d user for this property <d:AndroidGcmRegistrationId>" GCM Registration ID"</d:A
ndroidGcmRegistrationId>.
NOTE: Make sure that gcm.jar (Google provided library for client side GCM suppor
t) is added as part of dependent jars in the Android project.
2.3 Code Snippet to receive GCM PUSH Notifications on Device
To receive GCM push notification on device we need to implement GCM base intent
service which are again provide by Google in your application.
GCMBaseIntentService will have many inbuilt methods, one of which is onMessage()
method, push notifications are received by this method.
Following is the code to implement onMessage method to get notifications
protected void onMessage(Context arg0, Intent intent) {
// TODO Auto-generated method stub
// this is when notif data is passed as headers
String data = intent.getStringExtra( "c2dm_data" );
Log.i(TAG, "new message= "+ intent.getStringExtra( "c2dm_data" ));
}
FURTHER INFORMATION
You can refer the following document http://scn.sap.com/docs/DOC-40298 to know h
ow to configure an application in SMP cloud Admin portal and to develop an andro
id application for onboarding to an application in SMP.
REFERENCES
1. SMP Documentation: https://help.hana.ondemand.com/mobile/frameset.htm?SMP_wel
come.html
2. Eclipse: http://www.eclipse.org/downloads/
3. Installing ADT plugin for Eclipse: http://developer.android.com/sdk/installin
g/installing-adt.html
4. Android SDK: http://developer.android.com/sdk/index.html
www.sap.com
2013 SAP AG. All rights reserved.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explor
er, StreamWork, SAP HANA, and other SAP products and services mentioned herein a
s well as their respective logos are trademarks or registered trademarks of SAP
AG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports
, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects prod
ucts and services mentioned herein as well as their respective logos are tradema
rks or registered trademarks of Business Objects Software Ltd. Business Objects
is an SAP company.
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, and other Sybas
e products and services mentioned herein as well as their respective logos are t
rademarks or registered trademarks of Sybase Inc. Sybase is an SAP company.
Crossgate, m@gic EDDY, B2B 360, and B2B 360 Services are registered trademarks of
Crossgate AG in Germany and other countries. Crossgate is an SAP company.
All other product and service names mentioned are the trademarks of their respec
tive companies. Data contained in this document serves informational purposes on
ly. National product specifications may vary.
These materials are subject to change without notice. These materials are provid
ed by SAP AG and its affiliated companies ("SAP Group") for informational purpos
es only, without representation or warranty of any kind, and SAP Group shall not
be liable for errors or omissions with respect to the materials. The only warra
nties for SAP Group products and services are those that are set forth in the ex
press warranty statements accompanying such products and services, if any. Nothi
ng herein should be construed as constituting an additional warranty.
.

Das könnte Ihnen auch gefallen