Google Play Services being proprietary software is not included in AOSP hence using GCM with open code requires use of the now deprecated GCM library.
The GCM repository is available from
https://code.google.com/p/gcm/source/checkout
As I am using GCM on the client side, the folder of interest to me is gcm/gcm-client-deprecated
If using GCM within the android's services, the library must be included to be built with the Android framework by copying it to the framework directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% git clone https://code.google.com/p/gcm/ | |
% mkdir <AOSP directory>/frameworks/base/core/java/android/gcm | |
% cp -r gcm/gcm-client-deprecated/* <AOSP directory>/frameworks/base/core/java/android/gcm | |
After rebuilding Android, GCM would be included in the framework and can be imported by apps/services eg. if using the GCM Registrar, import as follows.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
.. | |
other imports | |
.. | |
*/ | |
import com.google.android.gcm.GCMRegistrar; | |
/* | |
.. | |
Class code | |
.. | |
*/ |
2 comments:
If you're developing an app targeted for AOSP devices and can't bundle the GCM library with the OS since you do not have control over it, you can still deliver push notifications to your app using an alternative gateway.
Pushy (https://pushy.me/) offers a highly-reliable push notification gateway for Android apps that works independently from GCM / FCM, using its own background MQTT connection.
Full disclosure: I founded Pushy.
Post a Comment