Getting started with Java and Android Google App Engine

I am struggling to run the example below:

https://developers.google.com/eclipse/docs/getting_started

The first issue I ran into was not installing the โ€œGoogle Cloud Messaging for Android Libraryโ€ in the Android SDK (obviously I know).

But now I have a problem with automatically generated code in two files in an Android project: GCMIntentService.java and RegisterActivity.java

Errors:

  • GetDeviceInfo (String) undefined method for type Deviceinfoendpoint GCMIntentService.java
  • List of methodsMessages () - undefined for type MessageEndpoint RegisterActivity.java
  • The insertDeviceInfo (DeviceInfo) method is undefined for the type Deviceinfoendpoint GCMIntentService.java
  • Method removeDeviceInfo (String) undefined for type Deviceinfoendpoint GCMIntentService.java

I am using the Java SDK v1.7.0_15 on Ubuntu, but I also tried on Windows 7 with the Java SDK v1.6 and had the same problem. The latest platform is Android 4.2.2 and Google App Engine 1.7.7. Eclipse is Juno Service Release 2.

The problem is that they are not casting correctly, because there is a getDeviceInfo method for the inner class DeviceInfoEndpoint inside Deviceinfoendpoint (various capatilization).

I could try and fix it, but just wondering if I have something wrong in my setup for this to happen?

Any help would be appreciated.

+5
source share
2 answers

In your GCMIntentService.java class, add .deviceInfoEndpoint () after the endpoint object in the error lines, as shown below:

DeviceInfo existingInfo = endpoint.getDeviceInfo(registration) DeviceInfo existingInfo = endpoint.deviceInfoEndpoint().getDeviceInfo(registration) 

In RegisterActivity.java change the line

 messageEndpoint.listMessages().setLimit(5).execute(); 

to

 messageEndpoint.messageEndpoint().listMessages().setLimit(5).execute(); 
+3
source

I would make sure that you use the same version of the GCM API as for the JAR. There have been many changes.

I am using the following code with gcm-server.jar specified in 19718 bytes.

The code that I successfully use to send GCM messages to the device:

 public void sendMessage() { String notificationToken = mobileDevice.getPushNotificationCode(); String deviceType = mobileDevice.getDeviceType(); Sender sender = new Sender(BROWSER_API_KEY); Message message = new Message.Builder().addData("message", "blah blah").build(); String device = "<the key for the device you are sending to goes here>"; try { System.out.println("Sending message..."); Result result = sender.send(message, device, 5); System.out.println("Done sending message"); if (result.getMessageId() != null) { System.out.println("Got message ID: " + result.getMessageId()); System.out.println("Got error code name: " + result.getErrorCodeName()); System.out.println("result: " + result); String canonicalRegId = result.getCanonicalRegistrationId(); if (canonicalRegId != null) { // Database has more than one record for this device. // Replace all of this device records with this new id System.out.println("Got new canonical reg id: " + canonicalRegId); } } else { String error = result.getErrorCodeName(); if (error.equals(com.google.android.gcm.server.Constants.ERROR_NOT_REGISTERED)) { // application has been removed from device - unregister from database System.out.println("Got error: " + error); } } } catch (Exception e) { e.printStackTrace(); } } 
+2
source

All Articles