GCM docs: http://developer.android.com/google/gcm/gs.html
- Set up Google Play SDK Using the SDK Manager, essentially install all Google Extras (at the bottom of list) Make sure you download the Google API SDK, and select that one in IntelliJ as the chosen SDK;
copied the
google-play-service_lib
into my own copy (as the documentation says):$ cp -r ${ANDROID_SDK}/extras/google/google_play_services/libproject/google-play-services_lib/ ~/Dev/
Created a new
module
in IntelliJ:File / Import Module...
- Pick the directory (
~/Dev/GooglePlay
) - Import module from external model --> Choose Gradle
- Use customizable gradle wrapper (whatever that means)
Make sure, in the Module Settings page to add the Android Framework 'nature' to this module, so the resources will be exported.
Add the dependency in your Project (use Module Settings / Modules, 'Dependencies' tab, click on
+
and pick thegoogle-play-service_lib
module)Remember to add the
google-play-services.jar
in thelib
directory as an exported dependency to thegoogle-play-service_lib
project and this project itself as a dependency to the Android client app.
Navigate to the Developers Console and create a new project. This gave me the following Project ID: empyrean-box-482
and then enabled Google Cloud Messaging for Android API.
You will need this Project ID (as the senderId
in the Android app): see Register for GCM section.
Using the steps below in Setting up a Keystore & Key I created a new API key, using this for the SHA1 signature:
BA:12:34:E3:ED:F5:B3:D9:65:35:84:87:C0:0F:85:BC:DB:40:75:06;com.alertavert.android.apps.cloudmessaging
The API key:
AIzaSyCGSzC3P82fjg1YNeznjcTt2qjGOkp0Ti4
This can be seen in the credentials page.
I used IntelliJ, could have been possible using keytool
but that didn't work initially. Selecting the project, choose Build / Generate Signed APK... then follow the instructions to create a new Keystore:
Location: ~/.android/debug.jks
Password: android
Key: debug_key
Password: android
$ keytool -exportcert -alias debug_key -keystore .android/debug.jks -list -v
Enter keystore password: `android`
Alias name: debug_key
Creation date: Feb 5, 2014
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Marco Massenzio, OU=eng, O=com.rivermeadow, L=San Jose, ST=CA, C=US
Issuer: CN=Marco Massenzio, OU=eng, O=com.rivermeadow, L=San Jose, ST=CA, C=US
Serial number: 52f2c0e2
Valid from: Wed Feb 05 14:53:22 PST 2014 until: Sun Jan 30 14:53:22 PST 2039
Certificate fingerprints:
MD5: 5F:9A:B6:9E:0E:55:82:8F:2A:71:00:C2:2E:DD:02:9A
SHA1: BA:12:34:E3:ED:F5:B3:D9:65:35:84:87:C0:0F:85:BC:DB:40:75:06
SHA256: E2:0C:53:67:21:4D:7B:DE:9E:6B:D3:7B:7D:3D:5E:72:BA:52:71:EC:63:0A:9A:50:4A:34:9B:BE:32:38:34:C2
Signature algorithm name: SHA1withRSA
Version: 3
Now you can use the SHA1 signature in the Google API project Public Key dialog
Using Apache HttpClient libraty (see example code in NotificationServer
) follow the instruction here to set up the POST request.
Make sure to remove Android SDK from the classpath for the server and replace it with the Java SDK, or you will get an impenetrable Stub!
exception.
A complete example can be found at the open source site
Mostly followed the GCM Client tutorial, still looking to find out where to import the WakefulBroadcastReceiver
(it's not part of the Google API SDK).