我希望收到解析推送通知,并打开一个列表活动,并开始活动之前使用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.
相关推荐
最新文章