Parse Push Notifications Android Example/Tutorial using Parse.com

Please follow and like us:

Android Push Notification using parse

Parse Push Notifications Android Example/Tutorial using Parse.com

Try latest Android Push Notification tutorial using Firebase Cloud Messaging (FCM)

Parse.com’s android push notifications tutorial gives very easy and simplest example for integrating android push notifications using parse.com. Parse.com use google’s CGM(Google Cloud messaging) service so we will get push very fast. Just do following few steps and your app will ready with android push notifications example. Best part parse.com’s android push feature we don’t worry about backend process, it will be taken care by parse.com

NOTE: if you are thinking to add Push Notification using parse.com with fresh account then you can’t create new account in parse.com. but if you have account already then you can implement it through this tutorial otherwise you can try our new tutorial for sending Push Notification using GCM, PHP and MySQL. part 1 for Server side configuration and part 2 for Android side logic for sending Push Notification.

Get GCM(Google Cloud Messaging) sender id for Parse Push Notifications using Parse.com

  • Login to Google API console using Gmail id.
  • On “API Project” dropdown, select “create a project…” option.
  • Add your Project name and create project
  • Enable Cloud messaging for android API from APIs (API & auth menu).
  • Create new server key from credential (API & auth menu)
  • Click On Home tab, you will get your project’s project number.

Server key and project number will use in our app

Get application id and client key from parse.com for Parse Push Notifications using Parse.com

  • Login/Signup to Parse.com
  • Create New App
  • Click App’s Setting -> Push menu
  • Add API Key and Sender Id which we have generate in google API console in “GCM Push Credentials”
  • Click App’s Setting -> Keys menu
  • Copy Application Id and Client key

add Application Id,Client key and project number in strings.xml file

Integrate Android Push Notifications using Parse.com with simple steps.

AndroidMainifest.xml file for android push notifications using parse.com will look like

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nkdroid.android.pushnotification">

    <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.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!--Change with your package name-->
    <permission android:name="com.nkdroid.android.pushnotification.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <!--Change with your package name-->
    <uses-permission android:name="com.nkdroid.android.pushnotification.permission.C2D_MESSAGE" />
    <application android:name=".app.MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
        
        <activity android:name=".SplashActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <activity android:name=".MainActivity" android:label="@string/title_activity_main"></activity>

        <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" />

                <!--Change with your package name-->
                <category android:name="com.nkdroid.android.pushnotification" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false">
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>

        <!-- add project number of google console project-->
        <meta-data android:name="com.parse.push.gcm_sender_id" android:value="@string/sender_id" />

        <!-- replace icon with your push icon identifier -->
        <meta-data android:name="com.parse.push.notification_icon" android:resource="@mipmap/ic_launcher" />


    </application>

</manifest>

style.xml for android push notifications demo will look like 

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="AppTheme" parent="AppTheme.Base">

    </style>


<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

        <item name="colorPrimary">@color/primaryColor</item>
        <item name="colorPrimaryDark">@color/primaryColorDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">@color/colorTextPrimary</item>
        <item name="android:textColorSecondary">@color/colorTextSecondary</item>

    </style>

</resources>

color.xml for android push notifications example will look like

<?xml version="1.0" encoding="utf-8"?>
<resources>

<color name="primaryColor">#2196F3</color>
<color name="primaryColorDark">#1976D2</color>
<color name="colorAccent">#FF4081</color>
<color name="colorTextPrimary">#212121</color>
<color name="colorTextSecondary">#727272</color>
</resources>

strings.xml for push notifications using parse.com will be looks like

<resources>
    <string name="app_name">Android Push Notification using Parse.com</string>

    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>

    <!-- parse.com keys-->
    <string name="applicationid" >app id</string>
    <string name="clientkey" >client id</string>

    <!-- GCM Sender ID -->
    <string name="sender_id" >id:project number</string>
</resources>

MyApplication.java contains initialization for Parse Push Notifications tutorial using parse.com

package com.nkdroid.android.pushnotification.app;

import android.app.Application;
import android.util.Log;

import com.nkdroid.android.pushnotification.R;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParsePush;
import com.parse.SaveCallback;


public class MyApplication extends Application {

    private static MyApplication sInstance;

    /**
     * @return ApplicationController singleton instance
     */
    public static synchronized MyApplication getInstance() {
        return sInstance;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        Parse.initialize(this, getResources().getString(R.string.applicationid), getResources().getString(R.string.clientkey));


        ParsePush.subscribeInBackground("", new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (e == null) {

                    Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
                } else {
                    Log.e("com.parse.push", "failed to subscribe for push", e);
                }
            }
        });

        // initialize the singleton
        sInstance = this;

    }


}

Hope you liked our simple Parse Push Notifications Example using parse.com, if you found any difficulty during integrating android push notification example using push notification then let me know via comments below.

Download complete example of Parse Push Notifications Tutorial using parse.com

nirav kalola