In Parse console it shows Delivery report as successful, but onPushReceive is not getting called at all. What am I missing here? any help would be appreciated.
Below is my code. Manifest code:
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.appname" />
</intent-filter>
</receiver>
<service android:name="com.parse.PushService" />
<receiver android:name="com.appname.PushReceiver"
android:permission="com.google.android.c2dm.permission.SEND"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</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.appname" />
</intent-filter>
</receiver>
PushReceiver class:
public class PushReceiver extends ParsePushBroadcastReceiver
{
@Override
protected void onPushReceive(Context context, Intent intent) {
super.onPushReceive(context, intent);
Log.v("Push Receive called...", "");
if (intent == null)
return;
try
{
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Add the permission:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
Check the receiver:
<receiver android:name="com.appname.PushReceiver" android:exported="false">
<intent-filter>
<action android:name="com.appname.INTERCEPT"/>
</intent-filter>
</receiver>
In Addition To The Permissions
There are a few things that cause Parse to not properly send the push notification. Parse does not do a great job at detailing them, but from what I have experienced with Parse, i can try to shed some light on things that are a not always so obvious.
If you are checking the Parse dashboard and are able to see your device register, that is good. However, you need to make sure that there is a deviceToken registered for that device. If there is not, I can almost guarantee that if you check your pushes tab, you will see that the success rate of that push was 0% or unsuccessful.
Making sure deviceToken is registering Other than simply initializing Parse, please make sure that the package name of your app matches that name which you use to link with in your Android Manifest. If that is not the case, that is most certainly a cause of not receiving pushes.
Intializing Parse
private void initializeParse() {
Parse.enableLocalDatastore(this);
Parse.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
Log.d(LOG_TAG, "Initializing parse with app id: " + getString(R.string.parse_app_id) + " client_key: " + getString(R.string.parse_client_key));
}
Listening For Pushes
public class ParsePluginReceiver extends ParsePushBroadcastReceiver {
private static final String TAG = "ParsePluginReceiver";
private static final String RECEIVED_IN_FOREGROUND = "receivedInForeground";
private static int badgeCount = 0;
public static final String FORWARD_EXTRA = "FORWARD_ACTIVITY";
@Override
protected void onPushReceive(Context context, Intent intent) {
JSONObject pushData = getPushData(intent);
if (pushData != null) {
Log.d(TAG, "JSON Payload: " + pushData.toString());
super.onPushReceive(context, intent);
}
}
protected void onPushOpen(Context context, Intent intent) {
JSONObject pushData = getPushData(intent);
Log.d(TAG, "JSON Payload: " + pushData.toString());
if (pushData != null) {
try {
super.onPushOpen(context, intent);
} catch (Exception ex) {
}
}
}
As reference, Parse Sdk is located here: https://parse.com/docs/android/guide
Side Note Parse is to be deprecated start of next year.
make sure you have all these permissions:
<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" />
<permission android:protectionLevel="signature"
android:name="your_package_name.permission.C2D_MESSAGE" />
<uses-permission android:name="your_package_name.permission.C2D_MESSAGE" />
And you need to add all of these to your Manifest:
<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" />
<category android:name="your_package_name" />
</intent-filter>
</receiver>
Just some advise, move on to something such as Firebase. Parse is shutting down.
Here're permissions you should have in your manifest:
<!-- Push Permissions -->
<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" />
<permission android:protectionLevel="signature"
android:name="your_package_name.permission.C2D_MESSAGE" />
<uses-permission android:name="your_package_name.permission.C2D_MESSAGE" />
Here're other stuff you should define in your manifest:
<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" />
<category android:name="your_package_name" />
</intent-filter>
</receiver>
Gradle dependencies:
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
With this manifest configuration i can successfully receive pushes from parse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With