Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 1    Views: 450

Ag-Chieve
Lost but trying
Profile
Posts: 124
Reg: Apr 16, 2012
Winnipeg
9,090
05/25/12 11:53 AM (13 years ago)

Adding Toast to Parse Push Notifications for Android (questions, not a how-to)

So I followed RidgeRock's excellent tutorial about adding Parse push notifications to an Android app and got it to work. But what I envisioned with push notifications was a message popping up in its own little window so a person could read it. I thought that's what they would do but instead they just flash by in a split second in the system tray and then disappear when tapped on the notifications page. (I think they're actually supposed to take you to the app, so I might've not integrated it exactly correctly.) Searching around on the 'net, I came across the Developing on Android Wordpress blog by Stefano Rago and he talks about adding Toast to the push notifications broadcast receiver. He supplies this bit of code: public class pushReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); String message = extras != null ? extras.getString("com.parse.Data") : ""; JSONObject jObject; try { jObject = new JSONObject(message); Toast toast = Toast.makeText(context, jObject.getString("alert")+ jObject.getString("title")+jObject.getString("action"), duration); toast.show(); } catch (JSONException e) { e.printStackTrace(); } } } I just don't know where I would put this code. I know the code that Parse supplies for the Push Notifications does mention a broadcast receiver (I assume you need that to even get the notifications) but it doesn't mention Toast, which I think is the piece that I want to get the notification to pop up in its own little window. So, where would one stick this code and would I need to replace some existing code with it or just shoehorn it in somewhere? Thanks.
 
Fred@mySkylla com
Android Fan
Profile
Posts: 5259
Reg: Oct 03, 2011
location unknow...
62,560
like
05/25/12 12:14 PM (13 years ago)
I would think this goes where the parse code goes. Haven't done parse, so ? Fred
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.