Push Notifications on Android Platform using a Rails web-server?
-
Hi, I have developed a small web application using Ruby on Rails (hosted on Heroku) that uses Facebook API and from time to time, my application has to notify the users about things. I have achieved this using the Facebook Notifications API. However, Facebook Notifications are received only on browser-fromt and not on my Android smartphone. On digging-deep, I found that Facebook doesn't relay all browser notifications to the smartphone and hence, the notifications from my app are not received on mobile device. I did some research to find ways that I can get my web-app users notified of these notifications on the mobile devices. Since I don't have experience in Android, I thought of building an Android app, which would display my app inside a WebView and would have Push Notifications enabled. The Android app would query my web-server for information to send Push notifications for. But, I found that WebView is really slow and I don't think it's the best way of doing it. Please let me know if I am missing something. Feel free to update the question if something can be paraphrased. Thanks in advance.
-
Answer:
You can either build a native android app and use a gem for Google Cloud Messaging (for Android on Rails) like https://github.com/spacialdb/gcm https://github.com/dondeng/gcm_on_rails In case you need to reuse your code for your web app, an alternative could be to develop a http://phonegap.com/about/ app that heavily uses web views within and use Push Notifications PhoneGap Plugin (http://phonegap.com/blog/build/introducing-genericpush-plugin/) for Android. Hope that helps.
Ashita Agrawal at Quora Visit the source
Other answers
I think what you are looking for is Google Cloud Messaging for Android. Its a service that allows you to send push notifications to android phone. Create a project in Google Console for your application. Obtain your project id and API key( Google for detailed procedure) and then in the mobile app you have to register the user to the GCM server and obtain the registration id of the user. Store this id in your server. Now whenever you get a notification from Facebook, make a post to GCM server with the registration id of the user. GCM will notify the android user with its push notification service. A similar question was asked on StackOverflow , you can follow my answer there too. Hope this answers your question :). link to my answer on stackoverflow: http://stackoverflow.com/questions/25228669/setting-up-server-side-for-gcm-in-an-android-app/25228724#25228724 link to go through for GCM setup: http://stackoverflow.com/questions/25228669/setting-up-server-side-for-gcm-in-an-android-app/25228724#25228724
Ashwin Surana
You can use websockets for ruby to establish the client-server communication. For example use the https://github.com/imanel/websocket-rubyhttps://github.com/imanel/websocket-rubyhttps://github.com/imanel/websocket-ruby for it.Apple Applications setup:-$ openssl pkcs12 -in <your .p12 filename> -out <your output .pem filename>.pem -nodes -clcerts app = RailsPushNotifications::APNSApp.new app.apns_dev_cert = File.read('path/to/your/development/certificate.pem') app.apns_prod_cert = File.read('path/to/your/production/certificate.pem') app.sandbox_mode = true app.save Android Applications setup:- app = RailsPushNotifications::GCMApp.new app.gcm_key = '<your app api key>' app.save WindowsPhone Applications setup:- app = RailsPushNotifications::MPNSApp.new app.cert = File.read('path/to/your/certificate.pem') app.save Apple notifications app = <Your Apple app> notification = app.notifications.create( destinations: [ 'Your first destination token', 'Your second destination token' ], data: { aps: { alert: 'Hello APNS World!', sound: 'true', badge: 1 } } ) GCM Notifications app = <Your GCM app> notification = app.notifications.create( destinations: [ 'Your first destination token', 'Your second destination token' ], data: { text: 'Hello GCM World!' } ) WindowsPhone Notifications app = <Your WindowsPhone app> notification = app.notifications.create( destinations: [ 'Your first destination url', 'Your second destination url' ], data: { title: 'Title', message: 'Hello MPNS World!', type: :toast } )
Sachin Pratap Singh
Related Q & A:
- How to send Push Notifications from iPhone?Best solution by Stack Overflow
- What is the difference between application server and web server?Best solution by Server Fault
- How to create a Restful web service in .Net Using MySQL?Best solution by stackoverflow.com
- How do I make a python web program that is on a ubuntu server allow access to the server?Best solution by Yahoo! Answers
- How to send image to web server?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.