简体   繁体   中英

Parse Push Notification received only on app restart

I am using Parse to push notifications to my application, but the funny thing is even though a notification is sent (confirmed via console) the notification is received by the device only when I force stop the app and restart the application! Is the Parse pushReceiver service going into sleep?

The following are snippets of my manifest and the broadcastReceiver, I have a toast to tell me when a push is received! This happens only on app restart.

Manifest :

    <service android:name="com.parse.PushService" />

    <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.aadisriram.buzzmessenger" />
        </intent-filter>
    </receiver>

    <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.aadisriram.buzzmessenger.SilentBroadcastReceiver" >
        <intent-filter>
            <action android:name="channelpush" >
            </action>
        </intent-filter>
    </receiver>

The broadcast receiver

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    String message = extras != null ? extras.getString("com.parse.Data") : "";
    JSONObject jObject;
    try {
        jObject = new JSONObject(message);
        String channelName = jObject.getString("channel_name");
        Toast toast = Toast.makeText(context, "Notif received", Toast.LENGTH_SHORT);
        toast.show();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

Alright, so I fixed the issue by updating my Parse SDK from 1.3 to 1.4! What I fail to understand is, if something worked on 1.3 for some amount of time how did it suddenly stop?

Weird issue, but the solution is upgrading to v1.4 of the Parse SDK.

try this may be it help you, i have successfully implemnted and my push is working..

<receiver android:name="com.parse.ParseBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
    <receiver android:name="your package name.YourCustomReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="your package name.UPDATE_STATUS" />
        </intent-filter>
    </receiver>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM