basic android push notification

Post on 03-Jul-2015

515 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

The presentation that was presented in Thailand Android Developer Day 2014 hosted by GDG Thailand.

TRANSCRIPT

ANDROID PUSH NOTIFICATION

Presented by CodeMobiles Co.,Ltd.

www.codemobiles.comFB Group: CodeMobiles Developers

WHAT IS PUSH NOTIFICATION?

USE CASES

NOTIFY INFORMTIONCONTROL APPLICATIONMAKE USERS TO COME BACKETC.

USE CASES (CONT.)

http://goo.gl/nmlw01

CMThaiDict

http://goo.gl/dG2exY

CMThai Lotto

http://goo.gl/25qFmI

SiamGold

Push APIs

WORKSHOPApp : CMPUSH

sourcecode

http://goo.gl/yK4Sq7

http://goo.gl/6gle34videos

WORKSHOP (STEPS)

1. New Project & Setup UI2. Create Parse Account and setup App ID3. Add Parse SDK4. Setup SDK5. Pray & Run6. Q&A

https://www.parse.com/products/push

Signup for Parse Account

https://www.parse.com/products/push

Download SDK

Add Lib: Parse-xx.jar

Modify AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<!-- IMPORTANT: Change "com.codemobiles.cmapppush" to match your app's package name. --> <permission android:name="com.codemobiles.cmapppush.permission.C2D_MESSAGE" android:protectionLevel="signature" />

<uses-permission android:name="com.codemobiles.cmapppush.permission.C2D_MESSAGE" />

Modify AndroidManifest.xml (cont.)

<service android:name="com.parse.PushService" /> <receiver android:name="com.parse.ParseBroadcastReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.USER_PRESENT" /> </intent-filter> </receiver> <receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

<!-- IMPORTANT: Change "com.codemobiles.cmapppush" to match your app's package name. --> <category android:name="com.codemobiles.cmapppush" /> </intent-filter> </receiver>

Create Application.java

public class Application extends android.app.Application {public Application() {}

@Overridepublic void onCreate() {

super.onCreate();

Parse.initialize(getApplicationContext(),"your app id - copy from parse setting","client id - copy from parse setting");

PushService.setDefaultPushCallback(this, MainActivity.class);

}}

COPY APP ID AND CLIENT KEYPaste into Application.java

Link Application.java Application in AnroidManifest.xml

<application android:allowBackup="true" android:name=“<your packagename>.Application" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >

MainActivity.java

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ParseAnalytics.trackAppOpened(getIntent()); PushService.subscribe(this, "free_version", MainActivity.class); new Thread(new Runnable() {

@Override public void run() { ParseInstallation.getCurrentInstallation().saveInBackground(); } }).start();

….. }

MainActivity.java

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ParseAnalytics.trackAppOpened(getIntent()); PushService.subscribe(this, "free_version", MainActivity.class); new Thread(new Runnable() {

@Override public void run() { ParseInstallation.getCurrentInstallation().saveInBackground(); } }).start();

….. }

Set Notification Title

Run App and Check if there is registered clients

Send Push Message

Evaluation

Follow USYoutube: CMDevFB Group: CodeMobiles DeveloperWWW.: CodeMobiles.comTraining: support@codemobiles.com Tel: +(66)87-676-0813-14

FB Group: CodeMobiles Developer

CMDev. Channel

CodeMobiles.com

Q&AFB Group: CodeMobiles Developer

http://goo.gl/bxWolr

THANK YOUfor Your Attention

top related