通过点击来自解析推送通知开放活动 [英] Open activity by clicking on the push notification from Parse

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

问题描述

我希望收到解析推送通知,并打开一个列表活动,并开始活动之前使用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();

我想有这样的作为默认值,而且还应该能够启动列表活动。 我也尝试过使用一个客户接收器,但我只能接收推的时候,不点击它时,直接打开该活动。

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

public class Push extends BroadcastReceiver {

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

我不知道的事情是我应该如何抓住推在后台说,它应该在用户单击通知打开与特定intent.putExtra(dataFromParse)名单的活动。我应该在哪里code,以及如何?在MainActivity,在列表活动,或做一些其他的与客户接收器?

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:{警告:测试,数据:store1}

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

@arvindwill希望这会有所帮助。

@arvindwill Hope this will help.

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

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