Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine Java and Android Getting Started

I've been struggling to get the example running from below:

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

The first problem I had was didn't have installed 'Google Cloud Messaging for Android Library' in the Android SDK (obvious I know).

But now I have an issue with the auto-generated code in two files in the Android project: GCMIntentService.java and RegisterActivity.java

The errors are:

  • The method getDeviceInfo(String) is undefined for the type Deviceinfoendpoint GCMIntentService.java
  • The method listMessages() is undefined for the type MessageEndpoint RegisterActivity.java
  • The method insertDeviceInfo(DeviceInfo) is undefined for the type Deviceinfoendpoint GCMIntentService.java
  • The method removeDeviceInfo(String) is undefined for the type Deviceinfoendpoint GCMIntentService.java

I'm using Java SDK v1.7.0_15 on Ubuntu but I also tried on Windows 7 with Java SDK v1.6 and had the same issue. Latest Android Platform 4.2.2 and Google App Engine 1.7.7. Eclipse is Juno Service Release 2.

The problem looks like they are doing some casting wrong, because there is a method getDeviceInfo for inner class DeviceInfoEndpoint inside Deviceinfoendpoint (different capatilisations).

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

Any help would be appreciated.

like image 725
reubenb87 Avatar asked Apr 16 '13 21:04

reubenb87


People also ask

What is Google App Engine used for?

App Engine is a fully managed, serverless platform for developing and hosting web applications at scale. You can choose from several popular languages, libraries, and frameworks to develop your apps, and then let App Engine take care of provisioning servers and scaling your app instances based on demand.

What two programming language do app engines tools use?

Google App Engine provides two possible runtime environments for applications: a Java environment and a Python environment. The environment you choose depends on the language and related technologies you want to use for developing the application.


2 Answers

In your GCMIntentService.java class, add .deviceInfoEndpoint() after the endpoint object in the lines with errors 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();
like image 141
Heigo Avatar answered Oct 29 '22 17:10

Heigo


I would make sure you are using the same version of GCM APIs as you have JARs for. There have been quite a few revisions.

I am using the following code with gcm-server.jar, listed at 19718 bytes.

The code I successfully use to send GCM messages to a device is:

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's 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();
    }
}
like image 40
Shellum Avatar answered Oct 29 '22 18:10

Shellum