I'm programming an Android App about share different content. Now I develop the social network, and when one user add new friend, send a Parse Push notification that the user add you.
I use Parse SDK, and I don't now how to do this.
I try this:
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("userId",id);
try {
installation.save();
This create a userId column in Installation class of Parse Data. (I see Parse Data and the userId column is the correct id from user)
Next I do:
//Create our Installation query
ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery();
pushQuery.whereEqualTo("userId",ParseUser.getCurrentUser().getObjectId());
// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pushQuery); // Set our Installation query
push.setMessage("Willie Hayes injured by own pop fly.");
push.sendInBackground();
I create a query that compare the userId colum (that contains the userId from user that add you) with the current ParseUser, but the Push don't send, and nobody receive.
Please help me.
Thanks.
What I did is I registered the device to a channel corresponding with the user. In Swift I did it like this, but in Android it would be very similar. This means that user "userId" would be subscribed to channel "user_userId".
let currentInstallation = PFInstallation.currentInstallation()
currentInstallation.channels = ["user_" + PFUser.currentUser().objectId]
currentInstallation.saveInBackground()
Then when you want to send the push, send it to channel "user_userId".
Related
I want to be able to send a notification to a user IF something changes.
For example, my application is crime-related. So users can submit reports of crimes that have happened in their neighborhoods.
When a new crime is reported, I want to be able to send ALL users in that specific neighbourhood a notification, even if they are not actively using the app.
How can this be done? I'm quite new at this but to my understanding services like Firebase Messaging require you to type out a message manually and select users to send the message to manually. I'm wondering if there's a way this can be done without someone having to manually do work?
Similar to how snapchat/instagram and stuff will send you notifications that someone has sent you a message even when you are not using your phone.
In my case, I just want the same standard notification "New crime in your area" to be displayed...
How can I do this? (Currently for notifications I'm just using Notification Channels), thank you so much!
You can easily do this using Parse Server through FCM integration.
First, you need to setup your Android app to be able to receive push notifications
Just follow this Quickstart: https://docs.parseplatform.org/parse-server/guide/#push-notifications-quick-start
Second, you need to create a cloud code function
I suggest you to create a cloud code function that will receive the neighborhood as parameter, will query for the user installations in that neighborhood and send the push notification to all of them.
It would be something like this:
Parse.Cloud.define('notifyCrime', async req => {
const query = new Parse.Query(Parse.Installation);
query.equalTo('neighborhood', req.params.neighborhood); // I'm supposing you have a field called neighborhood in your installation class - if not, you can save this field there when the user sign up
await Parse.Push.send({
where: query,
data: {
alert: 'There is a crime in your neighborhood'
},
useMasterKey: true
});
});
Reference: https://docs.parseplatform.org/js/guide/#sending-pushes-to-queries
Third, you need to call the cloud function from your Android app
Once some user has reported a crime, you can call the cloud code function that you created in step 2 to notify all other users in the same neighborhood.
It would be something like this:
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("neighborhood", "The neighborhood goes here");
ParseCloud.callFunctionInBackground("notifyCrime", params, new FunctionCallback<Object>() {
void done(Object response, ParseException e) {
if (e == null) {
// The users were successfully notified
}
}
});
Reference: https://docs.parseplatform.org/cloudcode/guide/#cloud-functions
"my understanding services like Firebase Messaging require you to type out a message manually and select users to send the message to manually".
This is not completely true. There is a method name Firebase Topic Messaging, that lets you send notifications to specific user segments only. You have to register from the app for that topic and then, you can send customized message to your user groups based on topics they subscribed to.
I am building an invitation form in which the user can fill an email or use a button that will open a contact app in his device and will get the email of a chosen contact(if email exists). I wonder if this kind of button is possible to achieve in Codename One without listing all the user's contacts in my app.
Thanks!
Itay
According to the official API, you may only use id to retrieve a certain contact using method getContactById(String id).
So, the answer is "No", you cannot get the contact by its email since you don't know the mapping id <> email
I am really rookie and need an advice.
I have read documentation, and as far as i understood if you need send direct message, follow next steps:
Make authentification, eventually you get Firebase TokenId and
userId
Send them to your server side and store it in DB
When you are going to send a message you need create json and put
inside topic text and resipent userId so on...
Send this json via HTTP to your server side
When server retrive this json, it should use Firebase API to
create new message bloc child with random name in firebase
Eventually server have to find recipent user in DB by userId that we get from message.
After server will find current recipent user by userId , next we should take firebase tokenId In order to sent notification .
And send recipent user notification with such data - name of new
message bloc child
Recipent will connect to this current bloc and retrive data
It is as i understood this consept, fix me please if smth wrong?
Your suggested approach sounds good. The most important thing to realize is that you require an app server to send a downstream message to a device. Using the database as the communication mechanism between the app and the app server is a popular approach.
You could also use Cloud Messaging's upstream capabilities. But I've never tried that approach, because the database works fine for me and I had little interest in learning yet another protocol (XMPP).
You can read how I implemented it in this Firebase blog post Sending notifications between Android devices with Firebase Database and Cloud Messaging.
I'm trying to find some ways to send a post notification to specific android device using its UUID , so I will do the following :
1 : login screen on android and then get UUID number from the device
2 : send this UUID to online database linked to userID
3 : I want to know how to send post notification to a specific UUID which I get from my database ?
Sending notification to android device using java is very easy.
If you want to push the notification directly from REST client, then you can refer this
If you want to send notifications from your java program, then follow these simple steps,
Add gcm-server.jar library file in your application
Create a Sender, that will send the notification
com.google.android.gcm.server.Sender sender = new Sender("pass your gcm api key here");
Then create a message object that will contain the data that you want to send
com.google.android.gcm.server.Message message = new Message.Builder().addData("key","value").build();
addData("key","value") in above code will add the key value in json to be send.
Then you can choose any of send method provided in Sender class
com.google.android.gcm.server.Result result = sender.send(message, device_token, no of retries);
There are total four version of send method available. You can find more detail about Sender class here
I have set up realtime feed update for user. So whenever a user comments or likes something, I get a update request from facebook.
{
object='user',
entry=[{
uid='1372299847',
id='1372299847',
time=1368760855,
changedFields=[feed]
}]
}
But this doesn't tell me what the update exactly was. I have to read that user's feed and see what is the new change and process it. If I get the id, then I can just request for that object and process it rather than reading his feed and getting the changes.
Is there any way to get what exactly was changed(id of the comment or status)?
Facebook doc says that you have to get the actual changeset via Graph API or FQL query. The notification you get tells you only the concerned user's ID.