I'm having a lot of trouble to get Google Cloud Messaging to work in my Phonegap-based app.
I'm following the instructions that are here.
It uses the PushPlugin, which I installed in my app according to the instructions.
Somehow I get no response after registering, nothing happens (no console.log appears) when I do :
window.plugins.pushNotification.register(
pushSuccessHandler,
pushErrorHandler, {
"senderID":"12345678",
"ecb":"onNotificationGCM"
}
);
var pushSuccessHandler = function(result) {
console.log(result);
};
var pushErrorHandler = function(error) {
console.log(error);
};
var onNotificationGCM = function(e) {
console.log(e);
switch(e.event) {
case 'registered' : {
console.log('android reg id: ' + e.regid);
break;
}
}
};
I setup an API project in Google Developer Console, got a project number that I used as the SenderID, and did all modifications to the Phonegap manifest and config xml files.
My app is not published yet in the Play store.
Is this necessary to get Cloud Messaging working?
And is the code above enough to get a 'reg id', or do I first need to push something from the server, but with what 'reg id' then??
Somewhere I read that the push notifications only work in a Phonegap-app when it is running, or when the notification is clicked, so not when the app is started from the normal icon. I don't understand this however, because aren't the notifications supposed to work when the app is not running?
Push notification will work without publishing, publishing is not required.
Only you have to get Sender ID from developer console.
Sender Id - its project number in developer console
for more detail you can check here
https://github.com/phonegap-build/PushPlugin
I am using it its woreking fine for both android and iOS
Update:
I'm using Intellij IDEA to build the app. When I compiled with phonegap build android the push notifications were working ok.
I had to add the 'android-support-v13.jar' and 'gcm.jar' files as a library in the Project Settings of the IDEA project, to get it working. These libraries need to be added to the Dependencies of the main module with scope 'Compile'.
Before I only added them directly in Dependencies of the module, with Scope 'Provided' but apparently that doesn't work (although it compiled).
Related
I just started a project in Unity and I integrated FireBase Analytics.
After some problems I was able to get data from IOS and Android devices so I added some custom events.
I followed the instructions from here and I stared to see results in the dashboard . My problem is that I'm not sure if both IOS and Android are sending the events and I don't know how to separate the event in the dashboard. I'm particularly concerned because I'm not sure if I misunderstood this line of the instructions:
The Firebase Unity SDK on Android requires Google Play services, which must be up-to-date before the SDK can be used. The following code should be added at the start of your application to check for and optionally update Google Play ....
I assumed that the following code had to be added ONLY for Android so I didn't add it to IOS. Can you tell me if I had add this code for IOS too? and how can I check the events for every OS?
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available) {
// Create and hold a reference to your FirebaseApp, i.e.
// app = Firebase.FirebaseApp.DefaultInstance;
// where app is a Firebase.FirebaseApp property of your application class.
// Set a flag here indicating that Firebase is ready to use by your
// application.
} else {
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
Thank you in advance
Well, I was looking for all the day and I found that the filter between OS is in the top left corner of dashboard and event tap as well.
I also used the code for both IOS and Android and I started to get custom event in IOS too.
I was asked to develop a sample app integrated with Amazon Pinpoint. Since I am not a pro at developing apps, I decided to follow this simple tutorial and develop the app following the steps described in it. The only differences are that, instead of using an emulator, I executed the project in my own cell phone (a Xiaomi Redmi 4x) and instead of GCM, I used Firebase.
At first, it seemed to work perfectly, but when I moved the app to the background and went back to my homescreen, I could no more receive push notifications from my app. When the app is open and running, everytime I send a push notification a pop-up appears with Title "New Notification" and buttons "Ignore"/"View". But when in background, nothing is visible in my system tray!
Also, if someone knows which part of the code is responsible for this notifications, just warn me and I upload it here.
Okay, so after some tests I made it work (not through console, but through CLI). To do so, I followed some steps I found this question, that took me to two other documents: one from Amazon teaching how to send push notifications through CLI and a simple but very detailed tutorial of phonegap-plugin, the plugin used in our Ionic application to process the pushes.
First of all, replace the phonegap-plugin in your app with the master version avaliable in the github link I sent you.
Then, putting all those information together, I figured out how to write a .json file containing the information we need to send the pushes. Here is a sample of the code I used:
{
"MessageRequest": {
"Addresses": {
"YOUR_DEVICE_ADDRESS_HERE": {
"ChannelType": "GCM"
}
},
"MessageConfiguration": {
"GCMMessage": {
"RawContent": "{\"data\":{\"title\":\"StackOverflow rocks!\",\"body\":\"Am I right?\",\"actions\":[ { \"title\":\"Yes!\", \"callback\":\"app.yes\", \"foreground\":true }, { \"title\":\"No!\", \"callback\":\"app.no\", \"foreground\":false }]}}"
}
}
}
}
As you can see, to change the content in the push notificationm, you'll have to edit it's "RawContent". To do so, use the phonegap-plugin tutorial I sent you and find out how to do the alterations you wish.
Last step: once you updated your plugin version AND saved the code above in a .json file (let's call it test.json), you can send it to your phone oppening command line in the folder containing your .json and writting:
aws pinpoint send-messages --color on --region YOUR_SERVICE_REGION --cli-input-json file:///test.json
This should do the trick! Hope it works for you. If any doubts, just let me know!
I am trying to integrate FCM notification in my project. I have Cloud Function backend, and app runs on android.
Below is cloud code to send notification:
exports.notificationTest = functions.database.ref(`/test/childA/childB/status`).onUpdate(event => {
const status = event.data.val();
console.info("Processing notificationTest cloud function")
console.info(`status : ${status}`)
const token = "EnterYourNotificationTokenHere"
const randomNum = Math.floor(Math.random() * 100)
var message = {
notification: { title : "My App", body : `Notification Test ${randomNum}`}
}
console.info(`Sending message on notification token`)
return admin.messaging().sendToDevice(token, message)
.then((response) => {
console.info("Successfully sent notification")
}).catch(function(error) {
console.warn("Error sending notification " , error)
})
})
On native Android app, I receive notification multiple times with interval of few mins.
Here, I have seen notification like this:
Notification Test 30
then after 2,4,8,16,32 mins of previous notification time I again get below message
Notification Test 30
I don't think I need to paste log here, because code is definitely executed just once (as the random number in notification stays the same).
So, why is this happening and how to fix it?
Below is my environment:
Native Android App
Using Android 7
Latest Android Studio Stable
Android Gradle Plugin - 3.1.1
Gradle - 4.1
Firebase-Ui - 3.1.0
Play Services - 11.4.2
Please try to reproduce in environment mentioned above.
I have resolved the issue by renaming my application package name
eg old name: com.xyz to com.xyz2
Using the new name i added this (new) android app to firebase project (it generated new app id). And the notifications started worked as expected (no retry).
But its a shame that I have to rename app package to resolve it. If this app was released in google play then I could not have renamed the app, else no one can get further updates on this app, and it becomes a new app!
It would still be great if some firebase developers could shed light on what is happening.
Recreating firebase project and recreating android project did not help when app name / top level package name were the same. Changing app name and relevant namespaces in existing android project fixed it for now.
Ideally I would like to know the proper fix for this and use the existing name rather than suffixing 2 at the end of app name.
I just had this same issue occur with my Ionic Android app. The same notification repeated after 2, 4, and 8 minutes. This seems to be an issue on the client side because it even happens when sending a message directly from the Firebase console.
I tried several things to fix it and it seems like the only way I could get it to work as intended was to make a new Android project and new Firebase app.
We are using azure easy API (node.js) for our mobile app. We have set up notification hubs already and have tested them - they all seem to be working. However, we are not sure how to invoke these notification hubs within the easy API - we have followed the entire documentation provided by Microsoft (e.g.: http://azure.microsoft.com/en-us/documentation/articles/notification-hubs-nodejs-how-to-use-notification-hubs/) and have tried out multiple things.
Can someone point to examples / code snippets on how to send push notifications specifically from Easy API?
thanks
Sankar
As for your situation, you could follow the steps below to achieve your purpose.
Once your notification hub is set up, go to the Settings menu for
your App Service and click on the Easy APIs option. Click on the +
Add button and fill in the form.
Click on the API and then click on Edit script. This will open Visual Studio Online. This will allow you to edit the script online.
edit notification.js file with following content:
var azure = require('azure-sb');
module.exports = {
"post": function (req, res, next) {
var hubname = 'yourhubname';
var connectionstring = 'yourconnectingstring';
var notificationHubService = azure.createNotificationHubService(hubname, connectionstring);
var payload = {
data: {
message: 'Hello!'
}
};
notificationHubService.gcm.send(null, payload, function(error) {
if(!error) {
res.status(200).send('succ');
}
});
}
};
Note: Replace your own hubname and connectionstring above.
Install azure-sb module through Kudu. Go back to the Azure Portal, select your App Servcie, then Tools, followed by Kudu. Click on the PowerShell version of the Debug console.
Change directory into site/wwwroot, then type the following into the console:
npm install –-save azure-sb
test your easy API by Postman:
Eventually, your client device will receive the notification:
Help it helps. Any further concern, please feel free to let me know.
Is there anyway to get device tokens without using Cloudpush modules. All I'm interested in is getting tokens and store onto my server and then I can push notification to registered devices.
I have tried to use it Cloudpush module from this link
http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.CloudPush
I followed these steps:
1) First Step :
Open this link https://developers.google.com/console/
than login with you account. Create a new project
i) "Creating a Google API Project",
ii)"Enabling the GCM Service"
iii)"Obtaining an API Key"
Image snap link : http://1.bp.blogspot.com/-AKAcUDtW0gg/UlK8rcpqUQI/AAAAAAAACuI/aq89OFZc2C4/s1600/all_steps.png
2) Second Step :
Click on this link https://cloud.google.com/console#/project
You can found you project that you already created.
Just Click on that and you found the Example: Project Number: 91060sdsdgsd
3) Third Step :
Now next step open this url https://my.appcelerator.com/apps
Login with your appcelerator account where you want to configure this vcm.
Click on your project than at the top side there are two option (Production/Development).
Click on Development. Now the main menu box will open in that there is 2nd (Second) tab click on that.
Now you found in that page Android Push Configuration
please fill this both fields
i) Google Cloud Messaging(GCM) API Key:
ii)Google Cloud Messaging (GCM) sender ID:
However all I'm getting is Failed receiving GCM SenderId.
As you already know the process to get keys/etc, so I wont rewrite it.
You asked to fetch the device token without Cloudpush , yes it can be done and you have to use a GCM module for this process.
Following info will be helpful in using module :
You can view the module's info at GCM Titanium.
The zip file of module is at in dist folder ( use latest version of zip ).
Example to use module is under example folder.
Hope it helps.