androidios push notifications

Parse Database:

It is a powerful cloud database .it’s provide lot of services like push notification services, and analytic tracking to your app etc.

Push Notification

Push Notification is  a service which is notify a user of new messages or events even when the user is not actively using your application.

Step 1: GCM Registration

Google Cloud Messaging (GCM) is a free service that helps developers send messages across multiple platforms: Android, iOS, and Chrome.

I. Sign in or Sign Up to your Google Developer Console you can use your google account.

II. Accept terms and conditions.

after that you can view your dashboard.

III. Create new project by clicking on drop down button and select that project after that

A page appears that shows your APP project ID and project number. You will use project ID later on as the GCM sender ID.

IV. To enable the GCM service by click In the sidebar on the left, select APIs & auth and turn the Google Cloud Messaging     for Android toggle to ON.V. To generate key by click In the sidebar on the left, select credential and click create new key button .VI. select server key and click create button please note down your API key.

Step 2 :Enable push notifications android App

I. Open your application and Add the following XML to your AndroidManifest.xml file immediately before the closing </application> tag

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 <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.parse.tutorials.pushnotifications" to match your app's package name.  
    -->  
    <category android:name="com.parse.tutorials.pushnotifications" />  
   </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>

II. Set permissions in your AndroidManifest.xml file,immediately before the <application> tag:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<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" />  
  <!--  
   IMPORTANT: Change "com.parse.tutorials.pushnotifications.permission.C2D_MESSAGE" in the lines below  
   to match your app's package name + ".permission.C2D_MESSAGE".  
  -->  
  <permission android:protectionLevel="signature"  
    android:name="com.parse.tutorials.pushnotifications.permission.C2D_MESSAGE" />  
  <uses-permission android:name="com.parse.tutorials.pushnotifications.permission.C2D_MESSAGE" />

Replace “YOUR_APP_ID” and “YOUR_CLIENT_KEY” with your Parse app’s id and client key.

V. To subscribe to the broadcast channel, add the following code to the onCreate method of your  Application class.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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);  
  }  
  }  
  });

Step 3:Parse Push Notification Settings

I. Go to your parse Push Notification Settings page then enable Client push enabled.

II. Enter your GCM Push Credentials on your parse Push Notification Settings page.

Now you can able send push Notification and you can also send sample Push notification by click on “send push notification ” button in parse Database.