Not pressed if the application is closed

Before marking this as a duplicate:

I read at least 15 similar threads, and each of them either uses the old Parse code (now obsolete setDefaultPushCallback), or the problem was caused by calling Parse.initialize (...) in the activity and not in the Application class. But this does not apply to my case. The official example (which I use) obviously does it right, so the code is already in the Application class.

I downloaded the Push Starter example from the official Parse instructions and tested it on an emulator. I get clicks only while the application is running. When it is closed (removed from the list of "recent applications" and not killed), I no longer get pushes. Which makes the whole function pretty useless ... I tried with and without GCM, the behavior is the same.

Any clues what could be wrong? All classes are examples in the warehouse, nothing changes or is not added by me (except for id / key and the call to ParsePush.subscribeInBackground, which I copied from the manual). Oddly enough, the sample code did not contain ParsePush.subscribeInBackground, and QuickStart does not mention it. It even gives a β€œTest” button, which supposedly sends a push that I never receive, with or without a subscription. The only way I have been able to get the push so far is to sign up for an InBackground subscription and send the push manually, although the web console is the only way if the application works. The web console also continues to report there 2 registered devices ... which is incorrect.

manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.parse.starter" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21"/> <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.RECEIVE_BOOT_COMPLETED" /> <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 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=".ParseApplication" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:allowBackup="true"> <activity android:name=".ParseStarterProjectActivity" 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.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.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 package name. --> <category android:name="com.parse.starter" /> </intent-filter> </receiver> </application> </manifest> 

ParseApplication:

 package com.parse.starter; ... public class ParseApplication extends Application { @Override public void onCreate() { super.onCreate(); // Initialize Crash Reporting. ParseCrashReporting.enable(this); // Enable Local Datastore. Parse.enableLocalDatastore(this); ParseUser.enableAutomaticUser(); // Add your initialization code here Parse.initialize(this, "***", "***"); ParseACL defaultACL = new ParseACL(); // Optionally enable public read access. // defaultACL.setPublicReadAccess(true); ParseACL.setDefaultACL(defaultACL, true); 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); } } }); } } 
+6
source share
2 answers

To clarify why you see this behavior, Parse has two different ways to deliver push notifications:

  • "Parse way": in the Parse SDK there is a component running in your application that supports connection to Parse servers. This will only work when your application is really running, because it is being killed by the connection to the Parse server.
  • GCM "Google" push address notifications: This works through Google Play Services, an application that always runs in the background and can launch your application when necessary. This will always work if you do not stop the application.

In your case, there is a package name conflict: com.parse.starter is the name of the package that was actually included in the example. This causes GCM to fail because it already knows the package under a different signature. Changing your package name to something unique, like com.parse.kaqqao , should solve the trick.

+1
source

There are several reasons for this:

  • There are two BroadcastReceiver: "com.parse.ParsePushBroadcastReceiver" and "com.parse.GcmBroadcastReceiver". I believe that the first receiver takes precedence over the GCMBroadcastReceiver, and thus the behavior is not affected by deleting or saving this receiver. It can also be triggered by the action "com.parse.push.intent.RECEIVE", which can handle the action of RECEIVE push messages. If both receivers perform the same task for parsing a Push message (starting from the same service in the background), enable the intent filter inside the same receiver and allow it to process all kinds of push messages. Because GCMBroadcastReceiver contains C2DM permission.

  • Try changing the order of the two broadcast receiver tags in the manifest. (Save GCMBroadcastReceiver before ParsePushBroadcastReceiver)

  • This may be due to android: exported = "false", perhaps this prevents the receiver from listening to push messages sent by the server. Try changing to true.

+1
source

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


All Articles