Followed the official guide and correctly receive push notification when app is opened. When the app is in background I receive the notification but when clicking on the badge it crash. The same when the app is closed,but I don't receive any notification, it crash and give me the following:
E/com.parse.PushService﹕ The Parse push service cannot start because Parse.initialize has not yet been called. If you call Parse.initialize
from an Activity's onCreate, that call should instead be in the Application.onCreate.
Be sure your Application class is registered in your AndroidManifest.xml with the
android:name property of your <application> tag.
java.lang.RuntimeException: Unable to start service com.parse.PushService@4263802d0
with Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10 pkg=com.xxxxx.xxxxx
cmp=com.xxx.xxxxxx/com.parse.PushService (has extras) }: java.lang.RuntimeException: applicationContext is null.
You must call Parse.initialize(Context) before using the Parse library.
Tried to follow similar post but still not work.
public class Application extends android.app.Application {
public Application() {
}
@Override
public void onCreate() {
super.onCreate();
// Initialize the Parse SDK.
Parse.enableLocalDatastore(this);
Parse.initialize(this, "dzSJWNKJYWgfPykS90u9TlpWrqCljSsOI", "IEGU9e6mBqZsajxDlI5pFIV");
// Specify an Activity to handle all pushes by default.
PushService.setDefaultPushCallback(this, Welcome.class);
}
}
And:
public class Welcome extends Activity {
Context context;
SessionManagement session;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
Parse.enableLocalDatastore(this);
Parse.initialize(this, "dzSJWNKJYWgfrykS90u9TlpWrqCljSsOI", "IEGU9e6mBqZsajxDehmvQ149OILfpFIV");
// Track app opens.
ParseAnalytics.trackAppOpened(getIntent());
ParsePush.subscribeInBackground("Global", 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);
}
}
});
Here is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxxxxxx.xxxxxx" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.xxxxxxx.xxxxx.permission.C2D_MESSAGE" />
<uses-permission android:name="com.xxxxxxx.xxxxx.permission.C2D_MESSAGE" />
<application
android:name=".app.AppController"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Welcome"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- 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.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's package name.
-->
<category android:name="com.xxxxx.xxxxxxx" />
</intent-filter>
</receiver>
</application>
</manifest>
Sorry for eventual rendoundant code, it's result of many attempt. Anyone knows how can I fix it? Any help would be much appreciated.