I have been trying to send a simple push notification from one device to the other using parse and I am with no luck.
Lets say I have a twitter clone that has follow/unfollow feature, if for instance User-A begins to follow User-A all I am trying to do is notify User-A that he is now being followed by User-B
This is the simple code that I am running
ParseQuery query = ParseInstallation.getQuery();
query.whereEqualTo("userId", "0VZF1l5qyA");
// Notification for Android users
ParsePush androidPush = new ParsePush();
androidPush.setMessage("Your suitcase has been filled with tiny robots!");
androidPush.setQuery(query);
androidPush.sendInBackground();
Just to even make sure that it works, I hard coded the value in but still nothing is being sent. And it also not like the user that I am trying to target is not on the server.
This how my installation table looks
I think something as simple as this should just work. Or maybe I missing how push notifications work.
By the way I am able to send push notifications from the Parse web app.
FYI - I have read the entire section of this and still not getting it to work.
Addendum: I have this block of code in my main activity and modified my manifest to look like this.
// Associate the device with a user
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("user",ParseUser.getCurrentUser());
installation.put("userId",ParseUser.getCurrentUser().getObjectId());
installation.saveInBackground();
By default clients are not allowed to push notification. You MUST do the following else your app wont work!!
Related
I have a mobile app (both iOS and Android) created for an online shop. This particular version of the app is for the sellers only. There is a section in it that function as a helpdesk. Basically buyers can open tickets, send messages to sellers etc. So what I want to do is every time when a buyer does that, the seller should receive a push notification on his device.
The database that keeps records of buyers, sellers and everything else runs on a separate server. I can have some sort of a cron job to periodically check for new cases opened by buyers. I'm hoping to use Parse to handle push notifications.
Now where I'm a stuck at is how to associate my database server with Parse.
My current plan is something like this.
The app is launched and the seller is logged in for the first time. Parse SDK registers the device with its servers. Alongside this, using a separate web service, I was hoping to save the unique ID generated by Parse (Upon research, I found the suitable unique ID is called Installation ID) and the logged in seller's ID in my database as well.
When the cron job finds an open case, it retrieves the seller's ID that it should go to. Along with it, that Installation ID.
My server sends out a HTTP request to post a push notification to the device with that Installation ID using Parse's REST API.
One issue. They haven't specified a way to pass an Installation ID in their docs.
I want to know if this is possible? Or if there is a better way to go about this?
Pretty sure that is possible. First you can get the installationId via the PFInstallation:
PFInstallation.currentInstallation().installationId // swift
or
[PFInstallation currentInstallation].installationId // Objective-C
Dont know about android but probably similar
ParseInstallation.getCurrentInstallation().getInstallationId() // Java
https://parse.com/docs/osx/api/Classes/PFInstallation.html https://parse.com/docs/android/api/com/parse/ParseInstallation.html
Send the push
And then you actually have to send the push: Take a look at the Parse REST guide under "using advanced targeting".
You can use a curl query like the following:
curl -X POST -H "X-Parse-Application-Id: %appId%" -H "X-Parse-REST-API-Key: %api key%" -H "Content-Type: application/json" -d '{ "where": { "installationId": "%installationId%" }, "data": { "alert": "The Giants scored a run! The score is now 2-2." } }' https://api.parse.com/1/push
The important part here is the { "where": { "installationId": "%installationId%" } which sends the push message to only the Installations that match the query - exactly the one installation with the given id.
I just tried and got a push message only on specific device :)
I am new to use Parse push notifications for Android. I have successfully integrated parse push notification to my project and tested. It works fine, but I have a few questions related to this push notification service, which I am not able to find in the Parse documentation.
How do I customise the push notification's sound?
How do I send a push notification from the device itself, without using the parse console?
What is the unique Id that I must save in order to perform the above?
Thanks in advance.
How do I customise the push notification's sound?
By default when a push notification is received the BroadcastReceiver specified in AndroidManifest.xml with intentfilter specified <action android:name="com.parse.push.intent.RECEIVE" /> is called.
Parse.com provides a BroadCastReceiver com.parse.ParsePushBroadcastReceiver which just sounds the default notification sound of the device. It does not have code for a specific notification sound, if you want to change the notification sound for push by parse you would have to implement a new BroadCastReceiver with the intentfilter specified above and have the below code for a custom sound(its only a partial code for demonstration):
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(alarmSound);
How do I send a push notification from the device itself, without
using the parse console?
Push notification can be sent from a device to another device or from console to devices. Every Parse application installed on a device registered for push notifications has an associated Installation object. The Installation object is where you store all the data needed to target push notifications. Now there would be many app users and you would want to target a specific user, for eg an app collects username at the first installation of the app and sets it in Installation object shown as below:
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("userName", "ranjith"); //mobile 1
installation.saveInBackground();
Now to send notification to the username "ranjith" you would need to create a ParseQuery object with the condition -username=ranjith shown as below, this would send a push notification to username "ranjith".
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
ParseQuery pushQuery = ParseInstallation.getQuery();//mobile2
pushQuery.whereEqualTo("userName", "ranjith");
ParsePush push = new ParsePush();
push.setQuery(pushQuery); // Set our Installation query
push.setMessage("My first notification");
What is the unique Id that I must save in order to perform the above?
These are the 2 unique ids present within parse installation object and these are generated by parse and you would not need to worry about it, to target a specific user you can add a unique id/username field in Installation object as specified above,
installationId: Unique Id for the device used by Parse (readonly).
appIdentifier: A unique identifier for this installation's client
application. This parameter is not supported in Android.(readonly)
I want to send push notification to multiple users using parse backend. can i target a friends with Facebook id without creating channel?(in my app i integrated Facebook)
if not possible send me code with creating channel
Parse has different possibilities depending on which kind of account you have. I assume you have the free one so you CANNOT send push notifications to specific or multiple users with this kind of account. BUT you can send them through the website controller to just iOS or Android users which is the only option you have with the free account.
I actually encourage you to use channels to do so. I assume you already have the correct initializations as explained in the parse website (https://parse.com/docs/android_guide)
// Create our Installation query
ParseQuery pushQuery = ParseInstallation.getQuery();
pushQuery.whereEqualTo("channels", "Giants"); // Set the channel
pushQuery.whereEqualTo("scores", true);
// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pushQuery);
push.setMessage("Giants scored against the A's! It's now 2-2.");
push.sendInBackground();
I ultimately reccomend you to read this guide: https://parse.com/docs/push_guide#sending-queries/Android
I have a Json URL, which contains data about Latest Job Postings, I am successfully parsing the Json URL and able to display the top job postings in my ListView.
But my requirement is to create a push notification, so that whenever a new job is posted, the user should be able to get a notification on device.
I have followed this: http://www.vogella.com/articles/AndroidNotifications/article.html
But I don't know how to get notifications in my case.
Could anyone help me?
Issue:
Give push notification to user's device about the updated data even when application is in background mode.
Solution:
Upon successful insertion of new data in your database (which is going to give updated set of data to your JSON request) , just call the file which send GCM push notification to all your users.
Reference:
GCM docs
GCM push-notification using php server
In context of implementation presented in demo app of 2nd link,
upon successful insertion,you can call send_message.php file,but make sure that $regId and $message should be retrieved from your database
You have created ActionBar Notifications for your app, but now you need to create the ability to receive notifications from a web client, instead of going to find them yourself from the URL.
To create a push notification you would need to have a constant thread (BroadcastReceiver) on the device that is waiting for the notification from the sever.
Google 'Cloud to Device Messaging' is the simplest way to do this.
This is a good link with lots of info on how to do this :
http://blog.mediarain.com/2011/03/simple-google-android-c2dm-tutorial-push-notifications-for-android/
If you require these notifications to be displayed on the device even when the application is not running (which seems to be the case from what you describe), you can use Google Cloud Messaging.
You would need a server that would poll the Json URL for updates, and send a GCM message to all the devices where your app is installed once such an update is detected.
Your app would have to register to Google Cloud Messaging and send the Registration ID received from Google to your server.
When your app receive a GCM message, you would create a notification and when the notification is tapped, you would start the activity that loads the data from the JSON URL.
I am trying GCM based android app to push messages from server to android client. I am able to push fix string with the following coe. I am wondering about the ways to push XML file from server and parse at the android application. I have done some research but I couldn't find push XML rather I found send XML file. Thank you
if (androidArray.size() == 1) {
String registrationId = androidArray.get(0);
Message message = new Message.Builder()
.collapseKey(collapseKey)
.timeToLive(30)
.delayWhileIdle(true)
.addData("message", Message)
.build();
Result result = sender.send(message, registrationId, 5);
You don't push xml (or JSON preferably) to the android app. You send a simple message to the app.
when the app receives the message it then needs to go and pull the xml/json from the website with an http get request to the relevant url that will supply the xml.
The android app can then parse the response and do whatever you want it to.
Here is an EXCELLENT tutorial on C2DM (The forerunner to GCM) http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html
You should be able to work out the differences needed.
UPDATE
Google Android has a complete section on GCM which can be found here
http://developer.android.com/google/gcm/index.html
Within that link there are getting started guides and a GCM Demo app
There are limits to the amount of data you can send and you should not rely on your data not ever exceeding the limits or Google arbitrarily changing the amount of data you are allowed to send.
Should either of those occur you would need to update your app so just do it right in the first place.
The message you send should act as a "key" to determine what action to take when the message is received.
UPDATE
If you are feeling REALLY adventurous you could use a custom sync adapter to help you consume your web services. It's pretty advanced stuff but if you are feeling curious about this then watch the Google I/O seminar on consuming RESTfull web services http://www.youtube.com/watch?v=xHXn3Kg2IQE