如何将“ParsePushBroadcastReceiver.getActivity”添加到应用程序?

时间:2014-10-26 15:00:11

标签: android parse-platform

我需要在getActivity的{​​{1}}方法中添加应用程序的哪个文件?

感谢。

3 个答案:

答案 0 :(得分:13)

如果您按照我这样的现有项目的文档进行操作,则不推荐使用:

PushService.setDefaultPushCallback(this,YourActivity.class);

这对我有用:

实现你的接收器并扩展ParsePushBroadcastReceiver类。

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)

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

答案 1 :(得分:1)

通常你应该将它添加到扩展ParsePushBroadcastReceiver的类中,例如。

public class YourBroadcastReceiver extends ParsePushBroadcastReceiver {

  ....
  protected Activity getActivity(Context context, Intent intent) {
    return yourActivity; // the activity that shows up 
  }
  ....

}

答案 2 :(得分:0)

在下面的代码的帮助下,在Receiver上写下你的ParsePushBroadcastReceiver以及你的活动。

public class ParsePushReciever extends ParsePushBroadcastReceiver {

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

注意:您的活动必须是启动器活动。