GoogleCloudMessaging Android Import Issue

2019-08-03 08:46发布

I am attempting to implement push notifications in an Android application, and I found plenty of examples, but they all import com.google.android.gcm - a package that has since been deprecated with (supposedly) its features folded into the GooglePlayServices package (I have version 15). I've tried to hook up that as well, and it does not work with the example code, and seems to require the deprecated package.

Does anyone have any up to date examples?

Any help would be greatly appreciated in figuring this out!

1条回答
戒情不戒烟
2楼-- · 2019-08-03 09:01

I wonder why you are looking for other example while google have provided you complete working code example including both server and client. What do you need is just to check out source code from here. Import project named "gcm-client" into work space. Add "google-play-services_lib" project from android sdk folder as a library. Change your SENDER_ID in DemoActivity located in com.google.android.gcm.demo.app package. That's it.

Please ignore samples/gcm-demo-client in same downloaded code directory. It uses old deprecated classes. You may reuse its utility class ServerUtilities to send/delete registration id to/from your server. [Thanks NickT for identifying ]

Edit:

Deprecated code is still exist as gcm-client-deprecated on given repository. Just ignore it and use gcm-client.

查看更多
登录 后发表回答