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)
Related
I want to make an app where one user can ask for help and all other using this app will get that notification. I am using Parse.com for this as server. i am totally new to this please help me.I got registered my device by key etc. now i can send push notification from parse.com to my device.
but don't know how to make this on my device to send this to other devices?
You can create subscribe devices to different unique channel names, then you can send notification containing required payload to the device using the channel to which other device is subscribed.
//subscribing to channel
ParsePush.subscribeInBackground("Channel_Name");
//getting installed devices
ParseQuery pushQuery = ParseInstallation.getQuery();
//query for getting devices with channel name
pushQuery.whereEqualTo("channels", "Channel_Name");
ParsePush push = new ParsePush();
push.setQuery(pushQuery);
push.setMessage("Your message payload");
push.sendInBackground();
You can subscribe multiple devices to same channel, but in this case when notification is send , it will be sent to all devices subscribed to a particular channel.
For more info: https://parse.com/docs/android/guide#push-notifications
my question is the same as this one:
android device specific push notifications by using azure mobile services
But I'm using .Net backend. This is the part where I send the notification:
Dictionary<string, string> data = new Dictionary<string, string>() { { "message", "this is the message" } };
GooglePushMessage message = new GooglePushMessage(data, TimeSpan.FromHours(1));
Services.Push.SendAsync(message);
but there is no way to pass in the registration ID.
UPDATE
I've also tried using the payload property of GooglePushMessage:
GooglePushMessage message = new GooglePushMessage();
message.JsonPayload = JsonConvert.SerializeObject(new { registration_id = "blablabla", data = new { message = "77" } });
It turns out that it is ignoring the registration_id property, because I'm still getting the notification on my device.
What I want to achieve is to get API calls from third parties and use the registration ids that I have stored in my DB to send notifications to specific devices.
Mobile Services uses Notification Hubs to handle it's push notifications. Notification Hubs filters push (i.e. does targeted push to specific devices, users, etc) using a Tag system. So if you want to be able to push to a specific Android Registration ID, when the device registers for Push Notifications with your Mobile Service, you should specify tags that you want to tie your registration to like so:
ToDoActivity.mClient.getPush().register(gcmRegistrationId, "tag1", "tag2");
If you want to push based off of the registration ID, you'd use that ID as one of your tags. Then from your .NET backend, when you call SendAsync, you can specify a tag (or tag expression) to target a specific device. So our call to push becomes:
Services.Push.SendAsync(message, registrationID);
The above text was incorrect. Tags are limited to 120 characters (https://msdn.microsoft.com/en-us/library/dn530749.aspx) and the GCM registration ID is too long for this. TODAY you're stuck with using an alternate tag that is less than 120 characters. If you have a UserID that is known on the device you could use that as a tag and then from your backend you can push to that specific User ID. Alternatively, you could generate a GUID on app launch and use that as a tag and then from your backend push to that GUID whenever you wanted to reach the specific device.
I'm new to Android, I'm developing an application which is a little bit similar to WhatsApp, I have different users, and I want when a User send a message, other users should receive a Push Notification.
So when a user add a new message, when a value will be inserted to the class, all the users should receive Push notifications.
I know how to send a push notification from the console, but I want push notifications to be sent automatically.
Thanks
You can send push notifications with parse by using channels whereby each user subscribes to a set of channels and you can send pushes to particular channels.
OR
You can use advanced targeting in which you use the installation class to select the devices.
ParseQuery<ParseInstallation> pq = ParseInstallation.getQuery();
pq.whereEqualTo("area", message3);
pq.whereEqualTo("group", message2);
pq.whereNotEqualTo("key", value);
// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pq); // Set our Installation query
push.setMessage("New Message");
push.sendInBackground();
Intent in = new Intent(Post.this,Notifications.class);
progress.dismiss();
startActivity(in);
OR
You can use cloud code to receive the data sent by the user and send push notifications to relevant devices
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!!
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