raudius / pushraven Goto Github PK
View Code? Open in Web Editor NEWA simple Java library to interface with Firebase Cloud Messaging (FCM) API. Pushraven allows you to push notifications to clients in very few lines of code.
License: MIT License
A simple Java library to interface with Firebase Cloud Messaging (FCM) API. Pushraven allows you to push notifications to clients in very few lines of code.
License: MIT License
OpenFeign or Retrofit are generally included to create REST API consumers along with OkHttp3 which has a better performance and API than HttpUrlConnection
Currently, only File is allowed to send to the PushRaven API
If the user is loading the JSON from environment variables, it is not feasible or secure to save that to a file and then provide to PushRaven
Secondly, files are not present in ephemeral file systems provided by services like Google App Engine and Heroku
Thirdly, a developer could have also loaded GoogleCredentials for personal use of Firebase in his app and reloading the InputStream for the same purpose inside Pushraven would be somewhat unnecessary
Hi,
I've encountered a bug when using your library.
After notification is properly set up, calling FcmResponse resp = Pushraven.push(myNotification)
doesn't actually send HTTP request to Firebase server. You have to call resp.getResponseCode()
or resp.toString()
afterwards for it to be sent.
The issue is described here and is caused by the way sending is implemented in Http(s)URLConnection
class.
Please add explicit call of e.g. getResponseCode
method after calling connect
here, probably in FcmResponse
constructor.
If adding it is not OK for some reason, please add info about this to README.
AndroidNotification.java line 50 reads
return (AndroidNotification) addAttribute("sound", mytag)
should read
return (AndroidNotification) addAttribute("tag", mytag)
Hi - thanks for this repo. It is very useful for me for android push notifications. Since FCM can be used for web push notification as well, I was wondering if this library could be used for that as well. Since it needs a server key, and the project in FCM seem to have only one server key, I was not sure how to use it for Web push. Pls throw some light on the same, as am bit new to this. Thanks for your help.
The singleton pattern is prone to synchronization errors and is not thread-safe. If multiple thread mutate the state of Push Raven, it will lead to an inconsistent state. The library is really great and I would like to contribute in it after some discussion over design patterns are done
I think we can achieve simpler syntax with production level design with minimal impact on current API
Dear developer, is it possible to target the user segment, like it can be done from the firebase website?
Thank you so much,
Roberto
How can I add custom sound and icon, what is the String I have to pass as a parameter ?
Hey! So if one follows the tutorial and inits the component like this:
Pushraven.setAccountFile(new File("service_account.json"));
<...>
Then the app enters an infinite loop and eventually crashes with a SO error:
Exception in thread "main" java.lang.StackOverflowError
at us.raudi.pushraven.Pushraven.setAccountFile(Pushraven.java:36)
at us.raudi.pushraven.Pushraven.setAccountFile(Pushraven.java:36)
at us.raudi.pushraven.Pushraven.setAccountFile(Pushraven.java:36)
<...>
That's is due to an infinite recursive call here:
https://github.com/Raudius/Pushraven/blob/master/Pushraven/src/us/raudi/pushraven/Pushraven.java#L36
At first glance, that recursive call seems superfluous, and can be just removed. Right? ๐
Best,
-Dmitry
Hi,
have you made an example or a tutorial?
Because when I add your Notification.java class I get an error which says that JSONObject.putAll method doesn't exist.
I check in maven, 1.1.0 is the latest. It is kinda confusing. Please advise.
in the version 1.0.1, it throws me this error:
Caused by: java.io.IOException: Server returned HTTP response code: 411 for URL: https://fcm.googleapis.com/v1/projects/olemojo-demo-fire/messages:sendResponse Code: 411
java.io.IOException: Error reading credentials from stream, 'type' field not specified.
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.fromStream(GoogleCredential.java:254)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.fromStream(GoogleCredential.java:226)
at us.raudi.pushraven.Pushraven.getAccessToken(Pushraven.java:132)
at us.raudi.pushraven.Pushraven.push(Pushraven.java:78)
at com.mojo.controller.PublicController.testPushRaven(PublicController.java:91)
It would be great to set a proxy parameter to pass it to the .openConnection() methods.
Hi,
I want to use this library in a web application ( in server side ) which is multi-thread. I need to send multiple notification in same time and i want to reduce creating new objects.
How should i use Pushraven object in this case?
Pushraven object is not singleton, am i right?
Hello,
How can you see whether or not the message was sent and acknowledged properly? The integration works as we are able to send messages directly from the firebase messaging page. However, we do not get any messaging while trying to send messages from the backend (based on Google App Engine).
How can we troubleshoot this? Is the only way to get this info through Google Play Console? If so, is it mandatory to publish the app or there is any other way around?
Thanks.
Hi
Already after sending a notification which has utf-8 title and body ( i test sending Persian characters ), in client side characters are not encoded correctly.
I modified a part of code in Pushraven class and i fixed it.
// Send POST body
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes( n.toJSON() );
wr.flush();
wr.close();
changed to:
// Send POST body
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(wr, "UTF-8"));
writer.write(n.toJSON());
writer.close();
wr.close();
wr.flush();
wr.close();
Hello, I created a firebase account and I am trying to send notifications to both (Android and iOS devices) but only Android is working. Is there any special step to work on iOS too?
I'm happily using this lil lib in production, works nicely, thanks! Any plans for Maven publication though? It makes deploying to platforms like Heroku much easier - I'd prefer not to have to commit your jar into VC.
Max
if i want send a message by the app package to broadcast .how can i do it?
whether it can send meessage only to ios or android ?
Hi there,
can I know how to use .addAttributeMap(key, map)?
//my code
Map<String,String> map=new HashMap<String,String>();
map.put("name","Amit");
map.put("abc","Vijay");
map.put("haha","Rahul");
Notification not = (Notification) new Notification()
.title(applicationName)
.body(notificationBody)
.addAttributeMap("extraField", map);
I got this error:
Error Message: '{ "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name "extra_field" at 'message.notification'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.