I can not receive push notifications in the application from Parse

I configured the Parse API in my application and everything works except for push notifications. I tried to send them from the site, but they do not come to the application. I did everything that is written in the documentation , but I can not receive notifications.

I was able to get one, and when I clicked, the application crashed. Now I tried to change something, but even with the reverse, I can no longer get them. How can I solve my problem?

EDIT: since some users may be interested, here are the parts of the code that I used for push notifications:

Main class (not MainActivity):

public class InstantsApplication extends Application { public void onCreate() { super.onCreate(); // Hidden Parse.initialize(this, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); ParseInstallation.getCurrentInstallation().saveInBackground(); 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); } } } } 

AndroidManifest (permissions are not included here, believe me, I set them):

 <!-- PARSE --> <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 package name. --> <!-- I have hidden package name root for this question --> <category android:name="com.xxxxxxxx.instants" /> </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> </application> 
+3
source share
1 answer

I met this problem before because you are using the latest Parse api. A few changes need to be made.

Firstly, in order to fix the error directly caused by push from the Parse backend, you need to declare a notification icon for parsing in the manifest.

  <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/ic_launcher"/> 

before the closing tag application.

Issuing another push from the backend will now give you a push notification as you expect. So far, so good. When you click this button, the application will crash again. To fix this, you need to remove the now obsolete call to PushService.setDefaultPushCallback(...) and add your own Receiver class. I did this in the * .util package just like the following:

 public class Receiver extends ParsePushBroadcastReceiver { @Override public void onPushOpen(Context context, Intent intent) { Intent i = new Intent(context, MainActivity.class); i.putExtras(intent.getExtras()); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } 

Then change the default Parse receiver to the one you just created: - Go to the manifest file.

  <receiver android:name="your.package.name.utils.Receiver" 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> 
+4
source

Source: https://habr.com/ru/post/1209411/


All Articles