1

I am trying to set up the sample project for Worklight push notification on Android. When I launch the app in the Android emulator only the first two buttons (isSubscribed and isSupported) are clickable. The other two buttons (Subscribe and Unsubscribe) remain disabled.

My steps are:

  1. Import the project into Eclipse
  2. Replace the SenderID and API Keys with the one obtains from GCM Console in application-descriptor.xml
  3. Deploy the PushAdapter (included in the project)
  4. Build and deploy
  5. Launch the Android application in the emulator

What is missing?

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
Minh Pham
  • 948
  • 12
  • 22

1 Answers1

3

For Push Notifications to work in the Android Emulator, you need to make sure to install in the Android SDK Manager:

Note: Push Notifications in the Android Emulator work only in an AVD running Android OS 4.x.x.

Next, you need to set-up GCM:
These steps are relevant whether you're using a device or emulator.

  1. Create a Gmail email address
  2. Go to GCM's web page: http://developer.android.com/google/gcm/gs.html
  3. Click on "Google APIs Console page"
  4. If you have never done step 3 above, you will be asked to create a project, this project will have an ID. This ID is the senderId value you place in application-descriptor.xml
  5. Click on "Create new Server key..." / "Create new Android key"
  6. The generated key is the API key value you place in application-descriptor.xml

Now you need to:

  1. Build and deploy the application
  2. Deploy the adapter
  3. Run the app on a device or emulator
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • I follow your steps but still not be able to set it up. On start up, it reports: "Failed to registering for push notification. The application will not be able to receive notifications". Do I have to a have server for push notifications? – Minh Pham Jun 11 '13 at 06:41
  • Is this emulator or actual device? Are you running Android OS 2.x or 4.x? If you use 2.x, your device must be synced with a Gmail address in Settings. If it is 4.x, you need to follow my above instructions. And yes, if you plan on using push notifications using Worklight, the app must connect to the Worklight Server. – Idan Adar Jun 11 '13 at 06:51
  • I'm on 4.x using an emulator. How can I setup the Worklight Server? – Minh Pham Jun 11 '13 at 06:55
  • By following the training module... Please edit your question with the full steps you've taken (from importing the project, to setting it up and running it on the device), perhaps you've taken a wrong step. – Idan Adar Jun 11 '13 at 06:56
  • See my edited answer for what you need to have installed if trying to use the Android emulator for push notifications; it would be simpler with a device if you have one... – Idan Adar Jun 11 '13 at 07:07
  • Make sure that you install the "Google Cloud Messaging for Android Library" in the Android SDK as well. – Idan Adar Jun 11 '13 at 07:33
  • Thanks Idan, it turned out I did not install GCM for Android Library. – Minh Pham Jun 11 '13 at 08:56
  • One further question, when the app launched, there's no login screen. How can I know which user I have registered for push notification so that I can use the associated `.jar` file to submit a notification? – Minh Pham Jun 12 '13 at 07:24
  • In the provided push notifications sample application, there is a login screen on application launch. If there isn't, you have changed something in the app. This is a only a sample app, you should not base a real application on it. It is there only to teach you the basics, based on the training module that sample belongs to... – Idan Adar Jun 12 '13 at 12:18