从android向AWS SNS主题发布消息

从android向AWS SNS主题发布消息,android,Android,我有一个应用程序,用户可以在其中键入消息。加载时,应用程序应该进行API调用,以从dictionary.com获取当天的单词。当用户键入该单词时 将用户输入的现有文本发布到AWS SNS主题。如果用户已输入名称,请在消息中包含该名称。我如何才能做到这一点?首先,从控制台获取您的AWS凭证 // AWS Iot CLI describe-endpoint call returns: XXXXXXXXXX.iot.<region>.amazonaws.com private stati

我有一个应用程序,用户可以在其中键入消息。加载时,应用程序应该进行API调用,以从dictionary.com获取当天的单词。当用户键入该单词时


将用户输入的现有文本发布到AWS SNS主题。如果用户已输入名称,请在消息中包含该名称。我如何才能做到这一点?首先,从控制台获取您的AWS凭证

 // AWS Iot CLI describe-endpoint call returns: XXXXXXXXXX.iot.<region>.amazonaws.com
private static final String CUSTOMER_SPECIFIC_ENDPOINT = "Your Specific End Point here";
// Cognito pool ID. For this app, pool needs to be unauthenticated pool with
// AWS IoT permissions.
private static final String COGNITO_POOL_ID = "Your Pool id here e.g us-west-2:7eed0766-71bb-4802";
// Name of the AWS IoT policy to attach to a newly created certificate
private static final String AWS_IOT_POLICY_NAME = "iotPubSub";

// Region of AWS IoT
private static final Regions MY_REGION = Regions.US_WEST_2;
// Filename of KeyStore file on the filesystem
private static final String KEYSTORE_NAME = "iot_keystore";
// Password for the private key in the KeyStore
private static final String KEYSTORE_PASSWORD = "password";
// Certificate and key aliases in the KeyStore
private static final String CERTIFICATE_ID = "default";
现在,使用您的主题名进行简单的调用,可以在中找到完整的代码,它还解释了如果您在控制台中查找凭据时遇到任何问题,如何获取凭据


希望这有帮助

您想向AWS主题发送消息??是。我想这样做让我和你分享代码
credentialsProvider = new CognitoCachingCredentialsProvider(
                getApplicationContext(), // context
                COGNITO_POOL_ID, // Identity Pool ID
                MY_REGION // Region
        );

        Region region = Region.getRegion(MY_REGION);

        // MQTT Client
        mqttManager = new AWSIotMqttManager(clientId, CUSTOMER_SPECIFIC_ENDPOINT);

        // Set keepalive to 10 seconds.  Will recognize disconnects more quickly but will also send
        // MQTT pings every 10 seconds.
        mqttManager.setKeepAlive(10);
  AWSIotMqttLastWillAndTestament lwt = new 
  AWSIotMqttLastWillAndTestament("my/lwt/topic",
                "Android client lost connection", AWSIotMqttQos.QOS0);
        mqttManager.setMqttLastWillAndTestament(lwt);

        // IoT Client (for creation of certificate if needed) 0316 5533564 873459
        mIotAndroidClient.setRegion(region);

        keystorePath = getFilesDir().getPath();