Push Notification is a service which notifies a user of new messages or events even when the user is not actively using your application. Let us see how to create an Android Push Notification Using Parse. As a top app development company, Perfomatix use Parse for notification in android.
Parse Database:
It is a powerful cloud database that provides a lot of services like push notification services and analytic tracking to your app etc.
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. Accept terms and conditions
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 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.
Need help? Android App Development Company
We are Perfomatix, one of the top mobile app development companies. We provide mobile app development services in building highly scalable android and iOS apps, and APIs. We also have strong expertise in IoT apps, Virtual Reality apps, and Augmented Reality apps. Get in touch with us to find out how we can help in shaping your disruptive idea into a prototype, MVP and finally into a killer product. Visit our success stories section to find out more about some of the startups which made it big with us.