I have parse notifications set up for my android app using Parse 1.7.1 sdk version.
But in the new android this method with parse says to call is depreciated.
PushService.setDefaultPushCallback(this, MainActivity.class);
But when it is removed the notification is sent from parse.com as I can see on the website but it does not arrive to the phone?
How can this be changed so that the push will arrive? Without using the depreciated method?
Thanks for the help in advance.
Try extending ParsePushBroadcastReceiver class and and use its
- OnPushRecieve (to do something before notification is shown in status bar)
- OnPushOpen (to do some action when user open's push for example open an activity)
- getNotification and
- onPushDismiss methods
And in manifest file replace
<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>
with this :
<receiver
android:name="com.example.parse.Notifications.NotificationsReciever"
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>
And if you want to open an activity onPushOpen, here is a sample:
@Override
protected void onPushOpen(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent i = new Intent(context, PushNotificationHandler.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
Here is a sample class that extends ParsePushBroadcastReciever class
public class NotificationsReciever extends ParsePushBroadcastReceiver {
@Override
protected Class<? extends Activity> getActivity(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
return ParseStarterProjectActivity.class;
}
@Override
protected Notification getNotification(Context context, Intent intent) {
// TODO Auto-generated method stub
return super.getNotification(context, intent);
}
@Override
protected void onPushDismiss(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onPushDismiss(context, intent);
}
@Override
protected void onPushOpen(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent i = new Intent(context, PushNotificationHandler.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
@Override
protected void onPushReceive(Context context, Intent intent) {
//here You can handle push before appearing into status e.g if you want to stop it.
super.onPushReceive(context, intent);
}
}