android – Deprecated setDefaultPushCallback and trackAppOpened methods

Question:

When using Parse, I noticed that some methods used in the examples of the PARSE website are deprecated ( deprecated ), among them the PushService.setDefaultPushCallback and the ParseAnalytics.trackAppOpened . Does anyone know how the replacement of these methods turned out?

Answer:

The ParseAnalytics.trackAppOpened(getIntent()) , commonly used in OnCreate been replaced by the ParseAnalytics.trackAppOpenedInBackground(getIntent()) . The PushService.setDefaultPushCallback method, used inside the application class ( extends Application ), did not have a method to replace it, but an implementation of the ParsePushBroadcastReceiver class, as shown in the example below:

public class Receiver extends ParsePushBroadcastReceiver {
    @Override
    public void onPushOpen(Context context, Intent intent){
        Log.e("Push", "Aberto");

        Intent i = new Intent(context, MainActivity.class);
        i.putExtras(intent.getExtras());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

Create this class, remembering to replace MainActivity.class with the class you want to call when opening the notification.

Now, finally, you must change the ArdroidManifest :

where was:

<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>

Now it's:

<receiver
        android:name="pacote.Receiver"
        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>

This is the replacement for the deprecated methods.

Scroll to Top