Failed to get push notification in Android using Parse

In the Parse console, it shows the delivery report as successful, but onPushReceive is not called at all. What am I missing here? any help would be greatly 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 package name.--> <category android:name="com.appname" /> </intent-filter> </receiver> 

Class PushReceiver:

 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(); } } } 
+8
android push-notification
source share
6 answers

Add permission:

 <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> 

Check receiver:

 <receiver android:name="com.appname.PushReceiver" android:exported="false"> <intent-filter> <action android:name="com.appname.INTERCEPT"/> </intent-filter> </receiver> 
+2
source share

Here are the 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 is another material that you must 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 get clicks from the syntax.

+2
source share

In addition to permissions

There are a few things that make Parse not send push notifications correctly. Parse does not do much work to drill them down, but from what I have experienced with Parse, I can try to shed light on things that are not always so obvious.

If you check the Parse control panel and can see your device recorder, that’s good. However, you need to make sure that the Token device is registered on this device. If this does not happen, I can almost guarantee that if you check the push tab, you will see that the success rate of this push was 0% or unsuccessful.

Make sure DeviceToken is logged In addition to simply initializing Parse, make sure the package name of your application matches the name you use to communicate with your Android manifest. If this is not the case, this is certainly the reason for not getting the shocks.

Parallel analysis

  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 taps

 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 a reference, Parse Sdk is here: https://parse.com/docs/android/guide

Side Note Pars should be deprecated early next year.

+2
source share

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 this 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 tell me, go to something like Firebase. The parsing closes.

+2
source share

Checking the installation object using the device token. (maybe you should set senderID)

below seems deprecated. Now I can not find anywhere from the parse docs. try adding the following permissions

 <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="com.appname.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.appname.permission.C2D_MESSAGE" /> 

These are the necessary permissions for the old version of sdk (possibly older than 1.10).

=============== New Part ====

I found the push sample code on github. https://github.com/ParsePlatform/PushTutorial/tree/master/Android

Below is a project that uses 1.11.0 sdk (1.13.0 can also work). https://dl.dropboxusercontent.com/u/82261293/Appname.zip

In my experience, some devices have a chance that without a device token. You must verify that it has been saved.

+1
source share

The parsing will be completely deleted.

I received mail from the parsing that they will retire. So why are you making those expired errors. Try using gsm or a socket that is lighter.

-one
source share

All Articles