1
votes

I've been playing with push notifications from parse.com for the past two days but can't get it to work.

I downloaded the sample code from parse.com and made some minor changes. On my parse.com dashboard I can see that the app is registered. When I send a push notification via the dashboard, I get a success message but I don't receive the notification on my Android emulator.

Here is manifest file:

<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (c) 2015-present, Parse, LLC.
  ~ All rights reserved.
  ~
  ~ This source code is licensed under the BSD-style license found in the
  ~ LICENSE file in the root directory of this source tree. An additional grant
  ~ of patent rights can be found in the PATENTS file in the same directory.
  -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.parse.starter" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

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

    <!--
      IMPORTANT: Change "com.parse.starter.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.starter.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />

    <application
        android:name=".StarterApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name="com.parse.PushService" />
        <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>
        <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.starter" to match your app's package name.
                -->
                <category android:name="com.parse.starter" />
            </intent-filter>
        </receiver>

    </application>

</manifest>

And here is the application class

public class StarterApplication extends Application
{
  @Override
  public void onCreate()
  {
    super.onCreate();

    Parse.initialize(this, "xxxx", "yyy");

    ParseInstallation installation = ParseInstallation.getCurrentInstallation();
    installation.put("email", "[email protected]");
    installation.saveInBackground();

    ParsePush.subscribeInBackground("Emulator1", new SaveCallback()
    {
      @Override
      public void done(ParseException e)
      {
        if (e != null)
          Log.d("#### DEBUG", "Parse subscription failed with error: " + e.toString());
        else
          Log.d("#### DEBUG", "Subscribed to parse");
      }
    });
  }
}

Can someone help? TIA

1
why don't you try this tutorial. I have done it and it works fine. - Kaveesh Kanwal
Does the installation object have a channel value? And then are you pushing to that channel? - Andrew Breen
Kavish: Thank you for the tutorial, but I opted for parse.com to avoid setting up my own server - Nisha Miller
Andrew Breen: Do I specifically have to set a channel value in the installation object? I specify a channel when I subscribe in background. When send push notifications from parse.com dashboard, I've tried using channel as well as email and both don't reach the device. - Nisha Miller

1 Answers

0
votes

Parse push notification require Google Play store & user to be signed-in the play store inside Android emulator to work. Follow platform and emulator specific instruction to enable google play store.