的推送通知打开活动

的推送通知打开活动

本文介绍了通过单击来自 Parse 的推送通知打开活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Parse 接收推送通知并打开 List 活动并在开始活动之前使用 intent.putextra("dataFromParse").我能够接收推送,但只能使用以下方法打开 MainActivity:

I want to receive a push notification from Parse and open an List activity and use intent.putextra("dataFromParse") before starting the activity.I'm able to receive the push but only open the MainActivity by using this:

PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();

我想将此作为默认设置,但也应该能够启动 List 活动.我也尝试过使用客户接收器,但是我只能在接收推送时直接打开活动,而不能在点击时打开.

I want to have this as the default, but should also be able to start the List activity.I have also tried using a customer receiver, but then I'm only able to directly open the activity when receiving the push, not when clicking it.

manifest.xml:

manifest.xml:

<receiver android:name="com.example.Push android:exported="false">
    <intent-filter>
        <action android:name="com.example.UPDATE_STATUS" />
    </intent-filter>
</receiver>

Push.java:

public class Push extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
      //Start activity
     }
}

我不确定的是我应该如何在后台捕获推送并说它应该在用户单击通知时使用特定的 intent.putExtra("dataFromParse") 打开 List 活动.我应该在哪里编码以及如何编码?在 MainActivity 中,在 List 活动中,还是对客户接收者执行其他操作?

The thing I'm not sure about is how I should capture the push in the background and say that it should open the List activity with the specific intent.putExtra("dataFromParse") when the user clicks the notification. Where should I code it and how? In the MainActivity, in the List activity, or do something other with the customer receiver?

推荐答案

已解决,默认活动为 MainActivity,但检查意图,如果com.parse.Data"中有内容,我将开始一个新的意图.

Solved it, having default activity as MainActivity, but checking the intent, and if there is something in "com.parse.Data" I will start a new intent.

Intent intent = getIntent();
Bundle extras = intent.getExtras();
String jsonData = extras.getString("com.parse.Data");
JSONObject json = new JSONObject(jsonData);
String pushStore = json.getString("data");
if(pushStore!=null) {
    Intent pushIntent = new Intent();
    pushIntent.setClassName(MainActivity.this, "package.name.List");
    pushIntent.putExtra("store", pushStore);
    startActivity(pushIntent);
}

然后用 json 发送一个推送:{ "alert" : "Test", "data" : "store1" }

Then just send a push with json: { "alert" : "Test", "data" : "store1" }

@arvindwill 希望这会有所帮助.

@arvindwill Hope this will help.

这篇关于通过单击来自 Parse 的推送通知打开活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 02:02