0

I've added Push Notification support using Parse to my app. It's working fine on most Android versions, but on Android 2.2 I'm getting a the following crash - I haven't actually even sent any Push Notifications, so this must be happening in the normal running of the app:

java.lang.RuntimeException: Unable to start receiver com.parse.ParsePushBroadcastReceiver: java.lang.NullPointerException
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:1871)
       at android.app.ActivityThread.access$2400(ActivityThread.java:118)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:998)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:130)
       at android.app.ActivityThread.main(ActivityThread.java:3756)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:507)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.NullPointerException
       at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:112)
       at org.json.JSONTokener.nextValue(JSONTokener.java:90)
.....

I've seen other threads about NullPointerException but they were always because the notification icon was missing from the manifest.

I don't know if it's because I also have my own alarm Receiver running for a daily alarm?

For what it's worth, here's what's in my AndroidManifest.xml:

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
...>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission android:protectionLevel="signature"
            android:name="[mypackage].permission.C2D_MESSAGE" />
    <uses-permission android:name="[mypackage].permission.C2D_MESSAGE" />

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

    <receiver android:name=".AlarmReceiver"/>

    <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="[mypackage]" />
        </intent-filter>
    </receiver>

    </application>
</manifest>
andygeers
  • 6,909
  • 9
  • 49
  • 63
  • As far as I know, Parse only supports API level 9+ which is Android 2.3+ – Björn Kaiser Feb 13 '15 at 14:50
  • Do you have any reference for that? It's strange that they haven't specified that in the library - normally you'd expect warnings / compile errors. I'm also not sure how to selectively disable it for Android 2.2 since I think it's the stuff that's in the AndroidManifest that's causing the issues rather than the initialisation code – andygeers Feb 13 '15 at 14:55
  • I don't have any public reference for that but remember a bug report where this was the issue. You can define the minSDKVersion in your build.gradle to exclude earlier Android versions AFAIK – Björn Kaiser Feb 13 '15 at 15:04
  • Hi! I have the similar issue in my app https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-xpa1/t39.2087-6/11057048_905765939490690_1397888161_n.png. I raised a bug https://developers.facebook.com/bugs/382310251966801 - without any success so far. In my case it is 4.4.2 and 4.1.1 on specific devices. The possible fix is to override onReceive and try-catch super(). – Dmitry L. May 05 '15 at 08:34
  • In case it's useful to others, there *is* a way you can selectively disable Parse for certain Android versions in the AndroidManifest.xml - I can't find a direct link right now specific to Parse, but as an example of how you would toggle something such as a service based upon the Android version see this answer to an unrelated question: http://stackoverflow.com/a/22643710/4397 – andygeers May 06 '15 at 08:51
  • Did you find an answer to your question? I am experiencing the exact same issue but on Android 2.3.4 – jahed Jul 23 '15 at 10:42
  • No - as per my comment above I just found a way to disable Parse entirely on 2.2 and 2.3 – andygeers Jul 23 '15 at 10:45

0 Answers0