iphone - Google App Engine (GAE)、Urban Airship、Java、推送通知。示例代码?

标签 iphone google-app-engine push-notification urbanairship.com

我的服务器在 GAE (Java) 上运行,我正在使用 Urban Airship 服务来传送推送通知。当然,当我使用他们的网络界面发送测试通知时,一切正常,但我想向我的 GAE 应用程序/服务器添加一个测试按钮,让 触发 UA 发送插入。

问题是,到目前为止我看到的所有示例都无法针对 GAE 的 Java 库进行编译。

有没有人想分享任何在 GAE 下构建和运行以通过 Urban Airship 触发推送通知的 Java 示例代码?

谢谢!

最佳答案

下面是一些在 GAE 下工作并通过 Urban Airship 发送推送通知的 Java 示例代码:

URL url = new URL("https://go.urbanairship.com/api/push/");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);

String appKey = "YOUR APP KEY HERE";
String appMasterSecret = "YOUR MASTER SECRET HERE";

String authString = appKey + ":" + appMasterSecret;
String authStringBase64 = Base64.encodeBase64String(authString.getBytes());
authStringBase64 = authStringBase64.trim();

connection.setRequestProperty("Content-type", "application/json");
connection.setRequestProperty("Authorization", "Basic " + authStringBase64);

String jsonBodyString = "YOUR URBAN AIRSHIP JSON HERE";

OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
osw.write(jsonBodyString);
osw.close();

int responseCode = connection.getResponseCode();
// Add your code to check the response code here

希望这对您有所帮助!

关于iphone - Google App Engine (GAE)、Urban Airship、Java、推送通知。示例代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3689108/

相关文章:

c# - OneSignal 推送通知 - 不适用于 WP8.1

iphone - 如何使用 AVCaptureSession 录制 mp4 文件?

iphone - 我如何泄漏内存?

iphone - 我可以使用 contentScaleFactor 安全地节省内存吗?

python - 什么会导致 Gdata Python 客户端在 appengine 中调用 YouTubeVideoQuery 时失败?

azure - 定期发送 Azure 推送通知

ios - NSUserDefaults 不适用于 IOS 8 模拟器

eclipse - GWT 部署到 Google 时遇到错误

image - 如何在 PIL 中将具有透明度的基于调色板的 PNG 转换为 RGB?

IOS - 未从 firebase 控制台收到 FCM 推送通知