[英]Google App Engine Java and Android Getting Started
我一直在努力从下面运行示例:
https://developers.google.com/eclipse/docs/getting_started
我遇到的第一个问题是没有在Android SDK中安装“用于Android库的Google Cloud Messaging”(显而易见,我知道)。
但是,现在我在Android项目中的两个文件中遇到了自动生成的代码的问题:GCMIntentService.java和RegisterActivity.java
错误是:
我在Ubuntu上使用Java SDK v1.7.0_15,但我也在Windows 7和Java SDK v1.6上尝试过,并遇到了同样的问题。 最新的Android平台4.2.2和Google App Engine 1.7.7。 Eclipse是Juno Service Release 2。
问题看起来好像他们在做一些强制转换错误,因为Deviceinfoendpoint内部的内部类DeviceInfoEndpoint有一个getDeviceInfo方法(不同的功能)。
我可以尝试修复它,但是只是想知道我的安装程序中是否有什么错误要发生?
任何帮助,将不胜感激。
在您的GCMIntentService.java类中,在带有错误的行中的终结点对象之后添加.deviceInfoEndpoint(),如下所示:
DeviceInfo existingInfo = endpoint.getDeviceInfo(registration)
DeviceInfo existingInfo = endpoint.deviceInfoEndpoint().getDeviceInfo(registration)
在RegisterActivity.java中,更改行
messageEndpoint.listMessages().setLimit(5).execute();
至
messageEndpoint.messageEndpoint().listMessages().setLimit(5).execute();
我会确保您使用的JAR版本与GCM API版本相同。 已经有很多修订。
我正在gcm-server.jar中使用以下代码,列出了19718个字节。
我成功用于将GCM消息发送到设备的代码是:
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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.