Android 将令牌注册发送到服务器不工作
我正在尝试向服务器发送推送通知,然后使用FCM和Amazon SNS将数据发送到客户端应用程序 我已经实现了以下功能Android 将令牌注册发送到服务器不工作,android,amazon-web-services,amazon-sns,Android,Amazon Web Services,Amazon Sns,我正在尝试向服务器发送推送通知,然后使用FCM和Amazon SNS将数据发送到客户端应用程序 我已经实现了以下功能 String customPushData = "my custom data"; CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest(); platformEndpointRequest.setCustomUserData(customPushDat
String customPushData = "my custom data";
CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest();
platformEndpointRequest.setCustomUserData(customPushData);
platformEndpointRequest.setToken(token);
platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
pushClient.setRegion(Region.getRegion(Regions.AP_NORTHEAST_1));
CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);
String endpointArn = result.getEndpointArn();
当我试着调试这个的时候。那么
光标没有从中移动
CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);
当我在console.aws.amazon.com/sns中签入我的应用程序时,没有注册令牌
我哪里出错了,如何处理以将数据发送到sns并返回到另一个设备
任何hep都将不胜感激 最后,我使用以下方法使其工作 我已经输入了
AsyncTask
,并做了以下更改
new AsyncTask<Void, Void, Void>(){
@Override
protected Void doInBackground(Void... params) {
AWSCredentials awsCredentials = new BasicAWSCredentials("access Key", "secret Key");
AmazonSNSClient pushClient = new AmazonSNSClient(awsCredentials);
CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest();
platformEndpointRequest.setToken(regToken);
platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
pushClient.setRegion(Region.getRegion(Regions.Region_Name));
CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);
Log.e("Registration result",result.toString());
return null;
}
newasynctask(){
@凌驾
受保护的Void doInBackground(Void…参数){
AWSCredentials AWSCredentials=新的基本凭证(“访问密钥”、“密钥”);
AmazonSClient pushClient=新的AmazonSClient(awsCredentials);
CreatePlatformEndpointRequest platformEndpointRequest=新建CreatePlatformEndpointRequest();
platformEndpointRequest.setToken(regToken);
platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
pushClient.setRegion(Region.getRegion(Regions.Region_Name));
CreatePlatformEndpointResult=pushClient.createPlatformEndpoint(platformEndpointRequest);
Log.e(“注册结果”,result.toString());
返回null;
}
我得到了endpointARN的响应。最后,我使用以下方法使其工作 我已经输入了
AsyncTask
,并做了以下更改
new AsyncTask<Void, Void, Void>(){
@Override
protected Void doInBackground(Void... params) {
AWSCredentials awsCredentials = new BasicAWSCredentials("access Key", "secret Key");
AmazonSNSClient pushClient = new AmazonSNSClient(awsCredentials);
CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest();
platformEndpointRequest.setToken(regToken);
platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
pushClient.setRegion(Region.getRegion(Regions.Region_Name));
CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);
Log.e("Registration result",result.toString());
return null;
}
newasynctask(){
@凌驾
受保护的Void doInBackground(Void…参数){
AWSCredentials AWSCredentials=新的基本凭证(“访问密钥”、“密钥”);
AmazonSClient pushClient=新的AmazonSClient(awsCredentials);
CreatePlatformEndpointRequest platformEndpointRequest=新建CreatePlatformEndpointRequest();
platformEndpointRequest.setToken(regToken);
platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
pushClient.setRegion(Region.getRegion(Regions.Region_Name));
CreatePlatformEndpointResult=pushClient.createPlatformEndpoint(platformEndpointRequest);
Log.e(“注册结果”,result.toString());
返回null;
}
我得到了endpointARN的回应