I would insist to first go through Android Docs and then try to implement using below steps.
Make sure you have installed Apache Tomcat and Apache Ant.
Steps:-
1.) Make sure you have dowloaded support library from SDK Manager -> "Google Cloud Messaging for Android Library".
2.) This will add "gcm" folder with demo application in your SDK folder.
3.) So go to "your_sdk\extras\google\gcm\samples\gcm-demo-server\WebContent\WEB-INF\classes\api.key". And here enter your API-KEY that you got from registering to
Google Console.
4.)
- Now you have to set System variables for Ant upto its "bin". So, edit Path and append it at the end using a semi-colon - "your_path\apache-ant-1.8.4\bin".
- Now set the user variable for "JAVA_HOME" - "C:\Program Files\Java\jdk1.6.0_23"(without "bin") and Ant upto its "bin" folder. Go to cmd and type ant.
Buildfile: build.xml does not exist!
Build failed
If you get above error means your Ant is working fine.
5.) Now go to "your_sdk\extras\google\gcm\samples\gcm-demo-server" and type ant.
If successful you will see output like,
init:
[mkdir] Created dir: your_sdk\extras\google\gcm\samples\gcm-demo-
server\build\classes
[mkdir] Created dir: your_sdk\extras\google\gcm\samples\gcm-demo-
server\dist
compile:
[javac] Compiling 7 source files to your_sdk\extras\google\gcm\sa
mples\gcm-demo-server\build\classes
war:
[war] Building war: your_sdk\extras\google\gcm\samples\gcm-demo
-server\dist\gcm-demo.war
dist:
BUILD SUCCESSFUL
Total time: 0 seconds
Also you will see a "dist" folder created with "gcm-demo.war" file.
6.) Now start your apache tomcat server and check that its working fine by running it using "http://your_host_ip:8080/"
7.) If its working fine go to "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\copy gcm-demo.war" here.
8.) Restart your Server and open the gcm-demo in browser - "http://your_host_ip:8080/gcm-demo/"
You will see result as,
Unregistered device #0
No devices registered!
So, server side is completed now.
9.) Now, import "gcm-demo-client" Application from "your_sdk\extras\google\gcm\samples\gcm-demo-client"
10.) Open "CommonUtilities.java" - here you need to give
SERVER_URL="http://your_host_ip/gcm-demo/" and
SENDER_ID="sender id you got from google console url".
11.) Build "gcm-demo-client" into your Android Device to register to your Server
Succesfully sent message to device #0
1 device(s) registered!
You will see above output if successfully registered will a send button.
12.) Press Send Button to get Notification on your device.
You can find the sorce demo from github, it also include the gcm-demo.war file that you have to deploy. The things that are required to be change are,
1.) API Key,
2.) SENDER_ID
3.) SERVER_URL
Thanks :)
Thank you for such a great explanation
ReplyDeleteI don understand step 4,
ReplyDeleteNow set the user variable for "JAVA_HOME" - "C:\Program Files\Java\jdk1.6.0_23"(without "bin") and Ant upto its "bin" folder. Go to cmd and type ant.
I already add JAVA_HOME(C:\Program Files\Java\jre6\) and PATH(;%JAVA_HOME%\bin;) to system environment. still not working..
'ant' is not recognized as an internal or external command,
operable program or batch file.
Setting JAVA_HOME - http://wso2.org/project/wsas/java/1.1/docs/setting-java-home.html
Deleteant - You have to Edit System Variables and add "apache-ant-1.8.4\bin" that is path of your ant upto "bin".
I am not able to execute step5.
ReplyDeleteI went up to "my_sdk\extras\google\gcm\samples\gcm-demo-server" in Command prompt and typed ant
The response is''ant' is not recognized as an internal or external command,
operable program or batch file.'
I could successfully execute the step up to 4.
Thanks in advance and thanks for this blog
That means you haven't set the System variable path for Ant - follow step number 4.
ReplyDeleteI got the Project Id and API Key but not able to run the application.
ReplyDeleteI have implemented all the steps described here, but my application is not running its showing force close after step 10.I am using ubuntu 12.Please help me.
I tried this its working Thanks to Lalit Poptani! Try this!!
ReplyDeleteNice tutorial working fine Thanks!!!!!!!!!!!!!!!!!!!!
ReplyDeletethanks a lot.............. thanks thanks!!!!
ReplyDeleteHi,
ReplyDeletei am unable to execute step 8. When i try to open the gcm-demo.war file using url "localhost:8080/gcm-demo"
it gives an error saying
"Not Found
The requested URL /gcm-demo was not found on this server."
Instead i have already copied the gcm-demo.war file into the webapps folder of Tomcat 7.0.
and my apache HTTP Server is running successfully and shows output "It works".
Thanks in advance
DeleteMe also have same problem. can you give solution?
DeleteAfter 11th step, I installed GCMDemo-debug.apk on my android device and started the GCM Demo apps and got following :
ReplyDeleteTrying(attempt 1/5) to register device on Demo Server.
Trying(attempt 2/5) to register device on Demo Server.
Trying(attempt 3/5) to register device on Demo Server.
Trying(attempt 4/5) to register device on Demo Server.
Trying(attempt 5/5) to register device on Demo Server.
Could not register device on Demo Server after 5 attempts.
From GCM : recoverable error
(SERVICE_NOT_AVAILABLE).
From GCM: device successfully unregistered!
Please help :(
Plz let me know if it's fixed, m also looking for solution
Deletehi, i have have the same problem....have you a solution?? plz
Deletemake sure you have Google Account in your Device. If you are testing in Emulator then also you need to add Google Account in it.
DeleteThis comment has been removed by the author.
ReplyDeleteif anyone not able to run ANT then try this,
ReplyDeleteGo to bin folder of ANT.....
C:\Ant\apache-ant-1.8.4\bin .... and then type ant as below
C:\Ant\apache-ant-1.8.4\bin>ant
Then try this
C:\Ant\apache-ant-1.8.4\bin>ant -buildfile C:\MyEclipse\SDK\extras\google\gcm\gcm-server\build.xml
It will run the build.xml from SDK
In the above my SDK was installed at C:\MyEclipse\SDK ,
Don't forget to change to your SDK location....
Thanks alot!
ReplyDeleteVery nice and quick tutorial.
After hours spent on the official android and google tutorial,
I read this one and everything worked!
Keep up the good work :)
Hi,
ReplyDeletei can register but i can not send message. i got error when i send message.
java.net.ConnectException: Connection timed out: connect
java.net.PlainSocketImpl.socketConnect(Native Method)
java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
java.net.Socket.connect(Socket.java:529)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:550)
com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
sun.net.NetworkClient.doConnect(NetworkClient.java:163)
sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:272)
sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:904)
sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
com.google.android.gcm.server.Sender.post(Sender.java:476)
com.google.android.gcm.server.Sender.post(Sender.java:455)
com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:170)
com.google.android.gcm.server.Sender.send(Sender.java:121)
com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServlet.java:82)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
thank you very much.
I have read the steps to run GCM demo on the Android. It is really good steps steps explained in this blog that is very helpful me and other user of Android So thanks for that.
ReplyDeleteAndroid App Development
How did you configue SSL for tomcat? the send message does not work
ReplyDeleteI have successed until the gcm-demo.war file creation under dist folder. But I couldn:t find "C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\" path in my pc. What should I do?
ReplyDeletedownload tomcat package in official site. Its a package..
DeleteThank nice work!
ReplyDeleteHello Lalit,
ReplyDeleteThanks for your post. I followed each steps you mentioned. Device registered to server but can not push message from server. It is giving below errors:
type Exception report
message HTTP Status Code: 401
description The server encountered an internal error that prevented it from fulfilling this request.
exception
com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401
com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177)
com.google.android.gcm.server.Sender.send(Sender.java:121)
com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServlet.java:82)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.41 logs.
Hello Everybody,
DeleteI found the solution. It may help someone who have same problem. I added API key to file samples/gcm-demo-server/WebContent/WEB-INF/classes/api.key, and it worked.
Thank you for your post.
I got this error while running apps :
ReplyDeleterecoverable error (SERVICE_NOT_AVAILABLE)
Your tutorial works properly in my machine..:) good job
ReplyDeletebut what about android mobile device i have installed apk ,it gives me successfully added but i wont get any notification from my serverside..
and one more is i want to use another machine tomcat then tell mi process for that i changed ip and all but it wont works..
please tell mii..
Thanks in advance..
Your tutorial works properly in my machine..:) good job
ReplyDeletebut what about android mobile device i have installed apk ,it gives me successfully added but i wont get any notification from my serverside..
and one more is i want to use another machine tomcat then tell mi process for that i changed ip and all but it wont works..
please tell mii..
Thanks in advance.
I got 404 error in gcm-server.. I am also follow your steps. other step completely work. But when i open page into browser i got 404 Error.
ReplyDeleteTnx adv.
When i am running ant command in step 5 it's giving some error and build failed.Can you help me on this.
ReplyDeleteHow can I get registration Id for GCM?
ReplyDeleteWonderful blog.. Thanks for sharing informative blog.. its very useful to me..
ReplyDeleteMobile App Development
Very nice post.Thanks for sharing such a informative post.
ReplyDeleteStartup Product Development
Glad to know about this one. really interesting and useful. Thank you.
ReplyDeleteThanks for providing such a useful info. Keep sharing posts like this..
ReplyDeleteDevOps Online Training
Thanks for such a great article here. I was searching for something like this for quite a long time and at last, I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays.iot certification chennai | iot training courses in chennai | iot training center in chennai | best iot training centre in chennai
ReplyDeleteUntuk memenangkan permainan, maka para penjudi harus mampu untuk membaca cara lawan dalam bermain. Memang kita tidak akan bertatap muka dalam bermain judi online
ReplyDeleteasikqq
http://dewaqqq.club/
http://sumoqq.today/
interqq
pionpoker
bandar ceme terpercaya
freebet tanpa deposit
paito warna
syair sgp
Great Post,really it was very helpful for us.
ReplyDeleteYaaron Studios is one of the rapidly growing editing studios in Hyderabad. We are the best Video Editing services in Hyderabad. We provides best graphic works like logo reveals, corporate presentation Etc. And also we gives the best Outdoor/Indoor shoots and Ad Making services.
Best video editing services in Hyderabad,ameerpet
Best Graphic Designing services in Hyderabad,ameerpet
Best Ad Making services in Hyderabad,ameerpet
I would like to thank you for the efforts you had made for writing this wonderful piece of writing.
ReplyDeleteChatbot app development company in Qatar
Blockchain Development Company in Qatar
Great Post,really it was very helpful for us.Thanks a lot for sharing! I found this blog to be very useful!!
ReplyDeleteAugmented Reality App development
Very Well said thank you for the great article!
ReplyDeletefree ebook for mobile app development
Great Post,really it was very helpful for us.
ReplyDeleteFree guide for macular degeneration glasses
Thanks for providing such a useful info. Keep sharing posts like this.
ReplyDeleteEye Health
Very nice post.Thanks for sharing such a informative post.
ReplyDeleteFind Content writers
Hey! Well written article. I would suggest this blog to my friends because he is working in one of the mobile app development company in India as an android app developer. I will share this article to him which will helps for his upcoming works. Thanks for sharing information with us.
ReplyDeleteThank you so much for the posting important blog.It's really awesome post.
ReplyDeleteMobile app development company in Singapore
Mobile app development company in Sydney
Mobile app development company in Australia
I really enjoyed your blog Thanks for sharing such an informative post.
ReplyDeletedigital marketing course in hubli
Very nice post.Thanks for sharing such a informative post.
ReplyDeleteTop mobile app development companies in Singapore
mobile app development companies in Sydney
This is a very good article and nice collection of information , would love to read more of such blogs and also know our services
ReplyDeleteThis is a very good article and nice collection of information , would love to read more of such blogs and also know our services
ninonurmadi.com
ReplyDeleteninonurmadi.com
ninonurmadi.com
ninonurmadi.com
Nino Nurmadi, S.Kom
Nino Nurmadi, S.Kom
Nino Nurmadi, S.Kom
Nino Nurmadi, S.Kom
Nino Nurmadi, S.Kom
Feeling good to read such a informative blog, mostly i eagerly search for this kind of blog. I really found your blog informative and unique, waiting for your new blog to read.
ReplyDeleteDigital marketing Service in Delhi
SMM Services
PPC Services in Delhi
Website Design & Development Packages
SEO Services Packages
Local SEO services
E-mail marketing services
YouTube plans
Hii, i came across this blog while random browing and found great content. Such information adds up new things in the memory for staying updated in this society. If you also want to visit some good web pages then do check out our website https://digiroads.in for more offers and discounts on digital marketing services.
ReplyDeletedigital marketing company in Jaipur
PPC company in Jaipur
seo company in Jaipur
social media marketing company in Jaipur
content writers in Jaipur
website development company in Jaipur
This comment has been removed by the author.
ReplyDeleteVery interesting article to read it. I would like to thank you for the efforts you had made for writing this wonderful article. This article inspired me to read more. Keep sharing on updated posts…
ReplyDeleteLearn Digital Marketing Course in Bangalore with Live Project Work & Case Studies taught by Ranjan Jena (10Yrs Trainer). 100% Guarantee to Clear Job Interview
This comment has been removed by the author.
ReplyDeleteHi, I Read your blog and I feel it is a very wonderful, informative blog . There are a lot of good information on this blog, I'd like to Share and I think people will get a lot of support from this blog. Thank you for sharing this informative blog, please keep up and share some unique posts with us in the future
ReplyDeleteecommerce website development services
Mobile App Development Company in bangalore
SEO company services
Web Design Company
Digital Marketing Agency
Packers and Movers
Service Apartments in Bangalore
https://www.sellbitbuy.net/paxful-clone-script
ReplyDeletehttps://www.sellbitbuy.net/uniswap-clone-script
Hello, I read your blog and find it to be very informative about Personal and Social Website Design. Please keep up the good work and continue to share more unique posts. I have a lot of good stuff I'd like to share, and I'm hoping that this blog will provide a lot of help to people. Thank you for sharing this informative blog.
ReplyDeletee learning & LMS app development company in India
e learning & LMS app development company in UK
e learning & LMS app development company in USA
e learning & LMS app development company in Dubai, UAE
e learning & LMS app development company in Kolkata
e learning & LMS app development company in Chennai
e learning & LMS app development company in Hyderabad
e learning & LMS app development company in New Delhi
e learning education & LMS app development company in Mumbai
nice informative post. Thanks you for sharing.
ReplyDeleteWordpress Development
Mobile App Development
I read your blog and find it to be very informative about Personal and Social Website Design. Please keep up the good work and continue to share more unique posts. I have a lot of good stuff I'd like to share, and I'm hoping that this blog will provide a lot of help to people. Thank you for sharing this informative blog.
ReplyDeleteMobile app development companies in Delhi
Educational app development
e learning & LMS app development company in UK
e learning & LMS app development company in USA
e learning & LMS app development company in Dubai, UAE
e learning & LMS app development company in Kolkata
e learning & LMS app development company in Chennai
e learning & LMS app development company in Hyderabad
e learning & LMS app development company in New Delhi
e learning education & LMS app development company in Mumbai
e learning education & LMS app development company in saudi arabia
I read your blog and find it to be very informative about Personal and Social Website Design. Please keep up the good work and continue to share more unique posts. I have a lot of good stuff I'd like to share, and I'm hoping that this blog will provide a lot of help to people. Thank you for sharing this informative blog.
ReplyDeleteMobile app development companies in Delhi
Mobile app development companies in Bangalore
Mobile app development in Bangalore
Educational app development
e learning & LMS app development company in UK
e learning & LMS app development company in USA
e learning & LMS app development company in Dubai, UAE
e learning & LMS app development company in Kolkata
e learning & LMS app development company in Chennai
e learning & LMS app development company in Hyderabad
e learning & LMS app development company in New Delhi
e learning education & LMS app development company in Mumbai
e learning education & LMS app development company in saudi arabia
HI guys,
ReplyDeleteThis is a very good post, and I like it very much. For us, it's insightful and helpful. For a long time, I've been looking for this and I'm just really pleased to say that I'm working with this stuff as well. Thanks for sharing this with us.
Digital Marketing Company in Jaipur
Digital Marketing company In Delhi
Digital Marketing Company in Bangalore
SEO Company in Jaipur
Website development Company in Jaipur
PPC Company in Jaipur
Digital Marketing Company in USA
HI,
ReplyDeleteI read your blog and I find that it is very informative about the personal and social design of the website. Please continue with good work and continue to share more unique publications. I have many good things that I would like to share, and I hope this blog gives you a lot of help for people. Thank you for sharing this informative blog.
Mobile app development companies in Delhi
Mobile app development companies in Bangalore
Mobile app development in Bangalore
Educational app development
e learning & LMS app development company in UK
e learning & LMS app development company in USA
e learning & LMS app development company in Dubai, UAE
e learning & LMS app development company in Kolkata
e learning & LMS app development company in Chennai
e learning & LMS app development company in Hyderabad
e learning & LMS app development company in New Delhi
e learning education & LMS app development company in Mumbai
e learning education & LMS app development company in saudi arabia
Excellent blog and I really glad to visit your post.
ReplyDeleteDigital Marketing Agency In India
Excellent post. Thank you for sharing
ReplyDeleteSpanish Language Learning| Spanish Language
Nice post, thanks for sharing.
ReplyDeleteMedicine for Hiv in India | Hiv Medicine in India | Best Hiv Medicine in India
Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome. You can also check my articles as well.
ReplyDeleteBest Homecare Services in Bangalore
caregiver services in bangalore
Thanks for providing such a useful info. Keep sharing posts like this.
ReplyDeleteonline pharmacy app development
telemedicine app development
hospital app development
clinic app development
doctor app development
Wonderful article. It's very useful.
ReplyDeleteIt looks like you have put lot of work into this.
SMARS designs jewelry to run along with your ever-changing wardrobe. A piece of Jewelry can either make or break your entire look; therefore, every unique outfit needs a different piece of jewelry to compliment it. But looking at the prices of traditional jewelry, we usually find occasions like festivals or ceremonies to buy it. And these adorable pieces spend most of their lives in the lockers. Komal, the founder of SMARS, understood this gap in the market. Every single piece is limited edition and walks hand-in-hand with trends. Adored by customers from all over the world, we ensure the quality delivery of our high-end, Indian fashion costume jewelry. Shop online for latest collection of Kundan, antique and temple jewelry in India check out necklace sets, earrings, bangles, chokers for girls and many more Indian jewelry sets for women available with free shipping across India.
Take a look: Latest Fancy Chokers For Girls Online
Having read your article. I appreciate you are taking the time and the effort for putting this useful information together.
ReplyDeleteBSc 1st Year Admit Card
BSc 2nd Year Admit Card
BSc 3rd Year Admit Card
thanks for your nice post
ReplyDeletestatic website design
ReplyDeleteHi,
Really interesting blog Oracle Online Training- NareshIT
Hi,
ReplyDeleteGood post. Full Stack Web Development Online Training - NareshIT