如何添加“ParsePushBroadcastReceiver.getActivity"到应用程序? [英] How to add "ParsePushBroadcastReceiver.getActivity" to an application?

查看:11
本文介绍了如何添加“ParsePushBroadcastReceiver.getActivity"到应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在应用程序的哪个文件中添加ParsePushBroadcastReceivergetActivity方法?

In which file of an application do I need to add getActivity method of ParsePushBroadcastReceiver?

谢谢.

推荐答案

如果您像我一样遵循现有项目的文档,则不推荐使用:

If you followed the documentation for an existing project like me, this is deprecated:

PushService.setDefaultPushCallback(this, YourActivity.class);

PushService.setDefaultPushCallback(this, YourActivity.class);

这对我有用:

实现您的接收器并扩展 ParsePushBroadcastReceiver 类.

Implement your receiver and extends ParsePushBroadcastReceiver class.

public class Receiver extends ParsePushBroadcastReceiver {

    @Override
    public void onPushOpen(Context context, Intent intent) {

        //To track "App Opens"
        ParseAnalytics.trackAppOpenedInBackground(intent);

        //Here is data you sent
        Log.i(tag, intent.getExtras().getString( "com.parse.Data" ));

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

然后,在你的 AndroidManifest.xml 中,(而不是使用 ParsePushBroadcastReceiver)

Then, in your AndroidManifest.xml, (Instead of using ParsePushBroadcastReceiver)

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

这篇关于如何添加“ParsePushBroadcastReceiver.getActivity"到应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆