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" /> <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" /> <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); } } }); } }
source share