Presentation is loading. Please wait.

Presentation is loading. Please wait.

Developing Push Notifications (C2DM) for Android Vijai Co-Founder Adhish Technologies, Sweet’N’Spicy apps.

Similar presentations


Presentation on theme: "Developing Push Notifications (C2DM) for Android Vijai Co-Founder Adhish Technologies, Sweet’N’Spicy apps."— Presentation transcript:

1 Developing Push Notifications (C2DM) for Android Vijai Co-Founder Adhish Technologies, Sweet’N’Spicy apps

2 What is Push Notification?

3 Without Push Notification

4 With Push Notification

5 Flow

6 Before we start It works on Android SDK 2.2+. You need a Google account Implementing with Device is easier than Simulator

7 Step 1 Register your email address for Google C2DM. http://code.google.com/android/c2dm/ signup.html

8 Step 2 – Manifest Changes Permissions to Send/Receive Messages <permission android:name="com.push.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />

9 Step 2 – Contd. Receiver for Messages <receiver android:name=".CustomC2DMReceiver" android:permission="com.google.android.c2dm.permission.SEND">

10 Step 3 – Receiver public class CustomC2DMReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals( "com.google.android.c2dm.intent.REGISTRATION")) { handleRegistration(context, intent); } else if (intent.getAction().equals( "com.google.android.c2dm.intent.RECEIVE")) { handleMessage(context, intent); } private void handleRegistration(Context context, Intent intent) { intent.getStringExtra("registration_id"); } private void handleMessage(Context context, Intent intent) { String message = intent.getExtras().getString("payload"); //Display Notification }

11 Step 4 – Display Notification Process the message and Display Notification NotificationManager manager= (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon,null, System.currentTimeMillis()); Intent notifyIntent = new Intent(Intent.ACTION_MAIN); notifyIntent.setClass(context, Home.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0,notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL); notification.setLatestEventInfo(context, “title", “message”, contentIntent); manager.notify(1, notification);

12 Step 5 – Ask Registration ID Async Service to get Registration ID Add it to the Launch if (Build.VERSION.SDK_INT >= 8) { Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER"); registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); registrationIntent.putExtra("sender", “silicondemo777@gmail.com"); startService(registrationIntent); }

13 Send Push Notification to the App – Trigged by Server Send HTTP POST to https://android.apis.google.com/c2dm/send Body : "collapse_key=Push&data.payload=Hi&registration_id=5245rc9e56g648f6.. ” Header : "Authorization: GoogleLogin auth=23232xx323232..” Google Login Auth Code: UserName - silicondemo777@gmail.com Password-silicon777silicondemo777@gmail.com http://bit.ly/googleauthcode

14 Best Practices Only right amount of Notifications Option to Opt out Track conversions

15 Questions Source Code: http://yousend.it/siliconpush

16 App gets Registration ID

17 Send message from Server

18 Shows Notification


Download ppt "Developing Push Notifications (C2DM) for Android Vijai Co-Founder Adhish Technologies, Sweet’N’Spicy apps."

Similar presentations


Ads by Google