The method setDefaultPushCallback(Context, Class<? extends Activity>) from the type PushService is deprecated

痞子三分冷 提交于 2019-12-10 20:47:17

问题


The whole problem i have been facing is with this line of code

PushService.setDefaultPushCallback(this, MainActivity.class);

on importing PushService the setDefaultPushCallback|() got deprecated. Why is this happening. I receiving the notifications but on tap app is being crashed. Also not receiving when the app isn't running.


回答1:


I have found the solution and it is quite simple.
I found the same question https://stackoverflow.com/a/26180181/3904085

" After spending few hours. Found a solution: Implement your receiver and extends ParsePushBroadcastReceiver class.

Receiver.java

public class Receiver extends ParsePushBroadcastReceiver {

    @Override
    public void onPushOpen(Context context, Intent intent) {
        Log.e("Push", "Clicked");
        Intent i = new Intent(context, HomeActivity.class);
        i.putExtras(intent.getExtras());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

Use it in manifest, (Instead of using ParsePushBroadcastReceiver)

Code for project's manifest:

<receiver
    android:name="your.package.name.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>

" Credits to @Ahmad Raza




回答2:


From Parse documentation on onPushOpen():

Called when the push notification is opened by the user. Sends analytics info back to Parse that the application was opened from this push notification. By default, this will navigate to the Activity returned by ParsePushBroadcastReceiver.getActivity(Context, Intent). If the push contains a 'uri' parameter, an Intent is fired to view that URI with the Activity returned by ParsePushBroadcastReceiver.getActivity(android.content.Context, android.content.Intent) in the back stack.

So if you override onPushOpen() like that, no analytics will be sent.

So here is my code:

public class Receiver extends ParsePushBroadcastReceiver {

    @Override
    protected Class<? extends Activity> getActivity(Context context, Intent intent) {
        return HomeActivity.class;
    }
}

You need to register the receiver like in the above post.

Tested with Parse 1.10.3



来源:https://stackoverflow.com/questions/26677029/the-method-setdefaultpushcallbackcontext-class-extends-activity-from-the-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!