直接向 Amazon SNS 注册设备 ID [英] Register device id directly with Amazon SNS

查看:22
本文介绍了直接向 Amazon SNS 注册设备 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Amazon Web Service 将推送通知直接发送到设备.安装应用程序后,我获得了设备 ID,我需要手动将其添加到 Amazon SNS.我想知道是否有办法在用户启动应用程序的那一刻直接向亚马逊服务器注册设备ID.

I am using the Amazon Web Service to send push notifications directly to a device. After I install the app I get the device id, that I need to manually add to the Amazon SNS. I would like to know if there is anyway to register the device id directly with the amazon server the moment the user starts the application.

我已经阅读了这篇,但发现这很困难了解.有没有人以前有过如何做到这一点的经验?

I have read this, but found it difficult to understand. Does anyone have any previous experience of how to do this?

编辑 2(到目前为止我所做的)

我已按照此链接中的说明操作>

I've followed the instructions from this link

  1. 我按照说明下载了snspoblepush.zip 文件,然后将项目解压并导入到eclipse 中.我添加 GCM 项目编号,添加 jar 文件并运行应用程序.我获得了我的设备注册 ID.

  1. I download the snspobilepush.zip file as instructed and extract and import the project into eclipse. I add the GCM project number, add the jar files and run the application. I get my device registration Id.

我打开 Amazon SNS,添加我的设备 ID 并发布一条消息.我在手机上收到消息.到目前为止效果很好.

I open the Amazon SNS, add my device id and I publish a message. I receive the message on my mobile phone. Works great so far.

我的问题

我的应用程序会有很多潜在用户.因此,将每个设备 ID 手动添加到 SNS 是没有意义的.我需要 Amazon SNS 在我启动应用程序时直接注册我的设备 ID.我有什么选择可以这样做吗?我在文档中找不到任何明确的答案.
此链接告诉我使用AWS Token Vending Service".但是,我找不到任何有关如何执行此操作的示例.

I would be having a lot of potential users for my application. So adding every device id manually to the SNS makes no sense. I need the Amazon SNS to directly register my device id when I start the app. Is there any option for me to do that? I couldn't find any definitive answer in the docs.
This link tells me to Use the "AWS Token Vending Service". However, I could not find any example of how to do that.

推荐答案

使用此处记录的 AmazonSNSClient:

Using the AmazonSNSClient documented here:

http://docs.aws.amazon.com/AWSAndroidSDK/latest/javadoc/

应该可以使用类似的代码进行注册:

it should be possible to register using code similar to this:

AWSCredentials awsCredentials = new BasicAWSCredentials("XXXXXX", XXXXXXXXXXXXXXX");
String platformApplicationArn = "arn:aws:sns:us-east-1:123456789:app/GCM/myappname";
AmazonSNSClient pushClient = new AmazonSNSClient(awsCredentials);

String customPushData = "my custom data";
CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest();
platformEndpointRequest.setCustomUserData(customPushData);
platformEndpointRequest.setToken(pushNotificationRegId);
platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);
Log.w(TAG, "Amazon Push reg result: " + result);

它不喜欢我的 ARN,但 Reid 指出这是一个愚蠢的错字,现在已在上面修复.

It was not liking my ARN, but that was a stupid typo that Reid pointed out and is now fixed above.

这篇关于直接向 Amazon SNS 注册设备 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆