Tuesday, May 28, 2013

Run GCM demo by app engine server

GCM api
1. Create google api project about GCM
2. Create server key. This api key will be used fot setting up server application.

Create App Engine project
1. Apply one project in app engine. Input project name and project url name.
    Peoject url name will be used in Android application.
2. Download App engine SDK for JAVA

  
Set up Server Application
1. Android SDK Manager, install Extras > Google Cloud Messaging for Android Library.
2. In a text editor, edit PATH_TO_ANDOIRD_SDK/extras/google/gcm/samples/gcm-demo-appengine/src/com/google/android/gcm/demo/server/ApiKeyInitializer.java and replace the existing text with the API key obtained above.
3. In a shell window, go to the PATH_TO_ANDOIRD_SDK/extras/google/gcm/samples/gcm-demo-appengine directory.
4. ant -Dsdk.dir=PATH_APP_ENGINE_SDK/appengine-java-sdk-1.8.0/ compile
    It will generate WebContent/. The code will be upload to App engine, so we don't need to launch server in our local side.

Upload Server Application to App Engine
1. From the appengine-java-sdk directory, run:
     bin\appcfg.cmd update PATH_TO_ANDOIRD_SDK/extras/google/gcm/samples/gcm-demo-appengine/WebContent/
2. Open http://appspot.com 
3. It should show "no devices registered" page.

Set up Android Application
  1. Using a text editor, open PATH_TO_ANDOIRD_SDK/extras/google/gcm/samples/gcm-demo-client/src/com/google/android/gcm/demo/app/CommonUtilities.java and set the proper values for the SENDER_ID and SERVER_URL constants.
  2. In a shell window, go to the gcm-demo-client directory.
  3. Use the SDK's android tool to generate the ant build files:
  4. android update project --name GCMDemo -p . --target android-16
4. ant clean debug
5. It will generate GCMDemo-debug.apk in bin/ folder
6. Install APK in devices.
7. Done.

No comments:

Post a Comment