Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Faiz Ahmed
42 PointsNotifications
Hey Ben! an you please show us how to enable notifications in our app so that the user is alerted when a new message appears!! Please!
1 Answer
Ben Jakuben
Treehouse TeacherAsk and you shall receive! But it won't be ready for a few weeks--I just recorded it yesterday. You need to first walk through this Quickstart guide: https://parse.com/apps/quickstart#parse_push/android/existing Make sure you get the latest version of Parse as there were Android Push bugs in earlier versions.
Then you need to go into your settings in your Parse app and enable client-to-client push notifications.
Then, add this on a successful login or signup:
protected void updateParseInstallation() {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put(ParseConstants.KEY_USER_ID, ParseUser.getCurrentUser().getObjectId());
installation.saveInBackground();
}
The idea is to associate the logged-in user with the ParseInstallation object.
Then, when you send a new message, add this:
protected void sendPushNotifications() {
// Create our Installation query
ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery();
pushQuery.whereContainedIn(ParseConstants.KEY_USER_ID, getRecipientIds()); // KEY_USER_ID = "userId"
// Send push notification to Parse
ParsePush push = new ParsePush();
push.setQuery(pushQuery);
push.setMessage(getString(R.string.push_message, ParseUser.getCurrentUser().getUsername()));
push.sendInBackground();
}
I'll explain it all in much more detail in the videos, but hopefully this gets you started!
Faiz Ahmed
42 PointsFaiz Ahmed
42 PointsThank you! Really helpful..