我一直在尝试将AWS 开发工具包用于推送通知。但是我遇到了错误。试图找到解决方案,但找不到太多支持。
iOS 和 Web 推送通知运行良好
一切已经设置和完成:
- AWS 后端和控制台设置到位。
- 身份池 ID 和其他密钥到位。
- ARN 主题到位。
安卓端:
AWS 开发工具包依赖项:
implementation 'com.amazonaws:aws-android-sdk-core:2.16.8' implementation 'com.amazonaws:aws-android-sdk-cognito:2.6.23' implementation 'com.amazonaws:aws-android-sdk-s3:2.15.1' implementation 'com.amazonaws:aws-android-sdk-ddb:2.2.0' implementation ('com.amazonaws:aws-android-sdk-mobile-client:2.16.8') { transitive = true; }
minSdkVersion 21
targetSdkVersion 29
在 onCreate 里面:
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider( getApplicationContext(), "My Pool Id here", // Identity pool ID Regions.US_EAST_1 // Region ); CognitoSyncManager client = new CognitoSyncManager( LoginActivateActivity.this, Regions.US_EAST_1, credentialsProvider); String registrationId = "MY_FCM_DEVICE_TOKEN"; **Instead of GCM ID, I am passing my unique FCM device token here. I searched, & it seems that wherever GCM is required, it is being replaced by FCM.** try { client.registerDevice("GCM", registrationId); } catch (RegistrationFailedException rfe) { Log.e("TAG", "Failed to register device for silent sync", rfe); } catch (AmazonClientException ace) { Log.e("TAG", "An unknown error caused registration for silent sync to fail", ace); } Dataset trackedDataset = client.openOrCreateDataset("My Topic here"); if (client.isDeviceRegistered()) { try { trackedDataset.subscribe(); } catch (SubscribeFailedException sfe) { Log.e("TAG", "Failed to subscribe to datasets", sfe); } catch (AmazonClientException ace) { Log.e("TAG", "An unknown error caused the subscription to fail", ace); } }
错误我在 client.registerDevice("GCM", registrationId);
原因:com.amazonaws.services.cognitosync.model.InvalidConfigurationException:未为 SNS 设置身份池(服务:AmazonCognitoSync;状态代码:400;错误代码:InvalidConfigurationException;请求 ID:a858aaa2-****** ****************)
笔记:
我尝试使用 Amplify 库,但即使这样也没有用。此外,在 iOS 和 Web 端,他们使用 AWS SDK。所以我也一定会使用相同的。这甚至不是特定于设备的错误。
我需要做的就是设置我的项目以获取推送通知。但我被困在最初的一步。无法为 Android 设备创建端点。