Parse Push is not working with Parse Sever - android

I am a newbie on parse server and have been using it with my android app. But I am having trouble with implementing push notifications. I do not know how to get logs so any guidance will be much appreciated! The installation class does not contain any "GCMSenderId" or "deviceToken".
Here is how I set up parse server to implement push notifications.
Parse Sever : 2.2.7
1) Developer Console
a) I create a new project using the new console and clicked on the overflow menu --> Project Info and got my project number.
b) Then I went to the "Credentials" page and clicked on Create Credentials --> Api Key --> Server Key and left everything default and clicked create.
c) I got the key for my project. Let it be "MY_API_KEY".
2) Now I setup my parse server app to use this api key and project number as you can see from the image.
enter image description here
3) Now I setup my android app manifest accordingly as you can see from the picture below.
enter image description here
I also added ParseInstallation.getCurrentInstallation.saveInBackground();in my app's Application class.
I am trying to send notifications using the parse dashboard
Please provide any help if possible, thanks!

to send push notification from parse server you have to implement cloud code
in Javascript or another programming language.
below is some code in JS to send push notification to a user
function(objectids,msg) {
var pushQuery = new Parse.Query(Parse.Installation);
msg.default="default";
pushQuery.exists("deviceToken");
pushQuery.containedIn('userObjectId',objectids);
try
{
Parse.Push.send({
where: pushQuery,
data: {
alert:msg.msgInfo,
str:msg,
sound:msg.default
}
}).then(function() {
console.log("push successfully sent");
}, function(error) {
console.log("error while send pn:"+error.code+":"+error.message);
throw "Push Error " + error.code + " : " + error.message;
});
}catch(error)
{
console.log("error while send pn:"+error.code+":"+error.message);
}
}

Related

Not getting the "MESSAGE_DELIVERED" Firebase event

I am trying to measure the latency between having a message exit Firebase Servers and being received on an Android app via the Firebase SDK. I have BigQuery integrated with my Firebase project, and have tried adding the following code:
// In the manifest:
<meta-data android:name= "delivery_metrics_exported_to_big_query_enabled"
android:value="true"/>
// In my Application object:
FirebaseMessaging.getInstance().setDeliveryMetricsExportToBigQuery(true);
The code seems to be exporting data to BigQuery. However, to calculate what I want I need timestamps for two different types of events associated to the same message id, "MESSAGE_ACCEPTED" and "MESSAGE_DELIVERED". Then, all I have to do is run a simple query that calculates the timestamp difference between those two.
My problem is: I can never seem to get the "MESSAGE_DELIVERED" variant for a given message id. I only ever get the "MESSAGE_ACCEPTED" side of the equation.
I am sending messages to the Android device via my own JavaScript app, and the request I make is like so:
app.get('/triggerAnt', function(req, res){
axios.post('https://fcm.googleapis.com/fcm/send', {
to:<TOKEN_FOR_DEVICE_GOES_HERE>,
notification:{
"title":"TESTNOTIFICATIONLATENCY",
"body":"TESTINGLATENCY"
},
fcm_options: {
analytics_label:<LABEL_HERE>
}
}, {headers: headers})
.then((response) => {
console.log(response.status);
}, (error) => {
console.log(error);
});
})
I would like to point out that the notification does effectively reach the device and I can open it too.
Is this delay on BigQuery's side or am I doing something wrong?
Thank you.

Xamarin forms push notifications from App Center - no messages getting through

I am trying to get push notifications working from a sample app. Whenever I send a message from App Center, I get 0/0 messages sent and I don't see anything happening in my app.
I followed the instructions at http://learn.microsoft.com/en-us/appcenter/push/xamarin-android. At the same time I implemented App Center Analytics. That seems to work since I can send TrackEvent messages and see them in App Center. I am building my app on VS Mac.
I set up the Firebase Cloud Messaging and got the Android API Key
I added the Nuget packages.
I didn't need to update the AndroidManifest.xml file.
I didn't do anything about ProGuard since I don't use it (or know what it is)
I didn't do anything about the OnNewIntent stuff - it's not clear how to tell if that's needed or how/where to do it.
In MainActivity.c I have the AppCenter.Start(..., typeof(Push), typeof(Anayltics), typeof(Crash));
In my App.xaml.cs I have
public App()
{
InitializeComponent();
if (!AppCenter.Configured)
{
Push.PushNotificationReceived += (Sender, e) =>
{
string summary = "Title=" + e.Title + " Msg=" + e.Message;
Console.WriteLine(summary);
};
}
AppCenter.Start("androidkey" + "ios=ioskey;", typeof(Push), typeof(Analytics), typeof(Crashes));
MainPage = new NavigationPage(new MyPage());
}
In my MyPage.xaml.cs I have
protected override async void OnAppearing()
{
base.OnAppearing();
Push.PushNotificationReceived += (Sender, e) =>
{
string summary = "Title=" + e.Title + " Msg=" + e.Message;
Console.WriteLine(summary);
};
I have put the google-servicesjson file in the main folder of the Android app and set its build action to GoogleServicesJson. I had to do that by manually editing the csproj file.
I put breakpoints at both console.write... statements and then never get triggered. Like I say, I send off a message from App Center and it never arrives.
Any thoughts or suggestions would be appreciated.
Thanks
Les

Ionic push not working - user not registered

I just had my first contacts with the ionic framework. I've worked with Phonegap and AngularJS before however, so it was not all that new to me.
I found out that there is this new feature to use Google Cloud Messaging push notifications in Ionic, through the Ionic Push feature (http://blog.ionic.io/announcing-ionic-push-alpha/).
Related lines of code from app.js
angular.module('starter', ['ionic','ionic.service.core', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleLightContent();
}
// enable push notifications
Ionic.io();
// enable users (http://docs.ionic.io/docs/user-quick-start)
// this will give you a fresh user or the previously saved 'current user'
var user = Ionic.User.current();
// if the user doesn't have an id, you'll need to give it one.
if (!user.id) {
user.id = Ionic.User.anonymousId();
// user.id = 'your-custom-user-id';
}
console.log('user-id:' + user.id);
//persist the user
user.save();
var push = new Ionic.Push({
"debug": true,
"onNotification": function(notification) {
var payload = notification.payload;
console.log(notification, payload);
},
"onRegister": function(data) {
console.log(data.token);
}
});
push.register(function(token) {
console.log("Device token:",token.token);
});
push.addTokenToUser(user);
console.log('token added to user');
});
})
Log from ionic serve
ionic $ 0 361081 log Ionic Core:, init
1 361083 log Ionic Core:, searching for cordova.js
2 361085 log Ionic Core:, attempting to mock plugins
3 361155 log user-id:1cc3d21c-b687-4988-b944-ad07b1a677c8
4 361158 log Ionic Push:, a token must be registered before you can add it to a user.
5 361159 log Ionic Push:, token is not a valid Android or iOS registration id. Cannot save to user.
6 361159 log token added to user
7 361160 log Ionic Push:, register
8 361160 error ReferenceError: PushNotification is not defined, http://localhost:8100/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js, Line: 2
9 361526 log Ionic User:, saved user
Any input is welcome, I am also more than happy to provide more information if needed.
EDIT 10/05/2015:
found out that dev_push = false only works on physical devices, not in browser
I tried to add token to user before even registering the user
I'm having the same problem, seems not many answers online at the moment.
but even on real device, it won't save the token to user.
I just had to decide go live without push first, then use ionic deploy to follow up.
also I think you have to put this line
push.addTokenToUser(user);
inside the register callback according to this doc
http://docs.ionic.io/docs/push-usage
You also need to declare 'ionic.service.push' as a dependency in your angular module if you'd like to use it.
angular.module('starter', ['ionic','ionic.service.core', 'ionic.service.push'])
I have it like this and it works:
Ionic.io();
var user = Ionic.User.current();
if (!user.id) {
user.id = Ionic.User.anonymousId();
// save our newly created user
user.save();
}
var push = new Ionic.Push({});
push.register(function (token) {
console.log("Got Token:", token.token);
// now we have token, so add it to user
push.addTokenToUser(user);
// don't forget to save user to Ionic Platform with our new token
user.save();
});
// set this user as current, so we can acess him later
Ionic.User.current(user);
Did you use this
ionic config set dev_push true-if testing in emulator or laptop
ionic config set dev_pushfalse - if testing on the phone
ionic push --google-api-key Your API Key
ionic config set gcm_key Project Number
Your token is the registration id that is unique for a particular device. That is sent to you by android.
Your Phone (With the API Key)---------> to Google's GCM
Google GCM (recognises it's you via your Project number and API key) -----> Oh it's you let me make a note of it. (Save a token id in it's DB and send's one to you.)
You get a registration id unique for your device(will change if an app is uninstalled).
You call your server say hey it's me your user. Please Notify me if you get something.
Server obliges, says, okay dude, I got this. Saves the registration id with your details probably your username in it's DB.
Now from Server.
I need to inform my users about a great deal(or an accident or something).
Pull up all targeted registration Id's from DB(maybe on some condition)
registrationIds.push(regId) //in a loop
and sender.send(message, registration, function(err, result){
});
Send to Google. Google see's oh only these many people(not all maybe) from this API Key need a notification. no Problem I will notify them and you receive a notification, my dear friend.
As mentioned in the link , Adding token to the $ionicUser is done by doing , user.addPushToken(pushToken); .
For this to work you should first configure the app not to use developement pushes by ,
ionic config set dev_push true
After initialising Ionic.io and Ionic.push , load the user or create one with a new random id ,
Ionic.io();
var push = new Ionic.Push();
Ionic.User.load(localStorage.id).then(function (user) {
Ionic.User.current(user);
pushFactory.register(push, user);
}, function (error) {
/*the user with that id is not present , so create one with a random id and register the push */
});
The push factory is defined as below,
function pushFactory() {
return {
'register': function (push, user) {
push.register(function (pushToken) {
user.addPushToken(pushToken);
user.save().then(function (answer) {
console.log('user saved'+answer);
})
})
}
}
}

how to make a chat between two people with android socketio module on nodejs server?

I work to develop a chat app with android on node.js server.I made a simple chat app.But everyone gets involved in the same room.I want to make a chat between only two people.How can I do that? What information should I send to the server?such as sender_name,receiver_name,message as a json format.
-How can I to do list online-users?
-And How can I start a chat between only two people?
What are the requirements for it?
This might help:
I'd recommend setting up namespaces for each room you have your chat in. I did something similar in my own code. Note: Rooms and namespaces are a little different from each other in socket.io itself (socket.io has both: http://socket.io/docs/rooms-and-namespaces/).
In the Server code:
I have a method under socket.on('connection') that is similar to
socket.on('groupConnect', function(group){
var groupNsp = io.of('/' + group);
}
This essentially makes sure that a namespace is exists under the name of the desired one. It doesn't mess it up or reset the namespace when it is called again.
Then for receiving the messages:
socket.on('message', function(data){
var msg = data.msg;
var nsp = data.nsp;
io.of(nsp).emit('message', msg);
}
You could also add the nsp to the data you have already and then just send the data again to the clients.
Then, in the client code:
var socketOut = io.connect('http://yourdomain:1337/');
var someGroupOrMethodToGetGroup;
socketOut.emit('groupConnect', someGroupOrMethodToGetGroup);
var nsp;
setTimeout(function(){
socket = io.connect('http://yourdomain:1377/' + someGroupOrMethodToGetGroup);
socket.on('message', function(msg){
displayMessage(msg);
}
nsp = '/' + someGroupOrMethodToGetGroup;
}, 1500);
Then in my displayMessage code I have:
socketOut.emit('message', { msg: desiredMessage, nsp: nsp });
From another answer of mine (https://stackoverflow.com/a/24805494/3842050).

Trying to implement Pushwoosh on PhoneGap build (Android)

I am trying to get my notifications to work however I am not receiving them. I followed the tutorial for implementing pushwoosh on phonegap build. I have my App ID and API Key from Google however I am not getting my device which the app is on to register when I reinstall the app.
I am guessing that my issue is in the following code:
// handle GCM notifications for Android
function onNotificationGCM(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
PushWoosh.appCode = "YOUR_PUSHWOOSH_APP_ID"; // my pushwoosh id is here
PushWoosh.register(e.regid, function(data) {
alert("PushWoosh register success: " + JSON.stringify(data));
}, function(errorregistration) {
alert("Couldn't register with PushWoosh" + errorregistration);
});
}
break;
I inserted this code in <script> tags within my index file however the device doesn't register what could be causing this issue?
I should also mention that I have the pushwoosh.js file within my javascript folder and I am pointing to it in my reference tags for .js files

Categories

Resources