![]() |
This post discusses how Android apps can use Amazon Web Services (AWS) to send e-mail without additional infrastructure. The sample code presented here uses Amazon Simple Email Service to record feedback from users but this same method could be used in the following scenarios:
Amazon Simple Email Service (Amazon SES) is a highly scalable and cost-effective bulk and transactional email-sending service for businesses and developers. Amazon SES eliminates the complexity and expense of building an in-house e-mail solution or licensing, installing, and operating a third-party e-mail service.
This post shows a sample for the Android platform. The complete sample code and project files are included in the AWS SDK for Android. A link to the SDK is available at the end of this post.
To use the AWS SDK for Android, you will need AWS credentials, that is, an Access Key ID and Secret Access Key. If you haven't already signed up for Amazon Web Services, you will need to do that first to get your credentials. You can sign up for AWS here. After you sign up, you can retrieve your credentials at this page.
The sample application described here demonstrates how Android apps can record feedback from their users through Amazon SES. It requires that you already have a verified e-mail address; this address will be used as both the sender and recipient of the message, so it is not necessary to get production access to Amazon SES before using this sample application. You can verify an e-mail address on the AWS console and read more about verification and production access in the Amazon SES Getting Started Guide. Amazon SES can also be used to create other types of e-mails not shown here.
Making requests to Amazon SES requires creating a client for the service. The code below shows how to create a client on both the iOS and Android platforms.
AWSCredentials credentials = new BasicAWSCredentials( PropertyLoader.getInstance().getAccessKey(), PropertyLoader.getInstance().getSecretKey() );AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient( credentials ); |
SES will accept both regular and raw e-mails. Our application makes use of the regular method, meaning we do not have to construct our own headers. Regular e-mails require a source, destination (list of to, cc, and bcc addresses) and a message, which itself comprises a body and subject. The code below shows how to create the various parts of the email on both the iOS and Android platforms.
String subjectText = "Feedback from " + nameField.getText();Content subjectContent = new Content(subjectText); String bodyText = "Rating: " + ratingBar.getRating() + "\nComments\n" + commentsField.getText();Body messageBody = new Body(new Content(bodyText)); Message feedbackMessage = new Message(subjectContent,messageBody); String email = PropertyLoader.getInstance().getVerifiedEmail();Destination destination = new Destination().withToAddresses(email); |
Once we've constructed our e-mail components, it simply becomes a matter of creating a SendEmailRequest
and passing this to the SES client we created earlier. The code below shows how to create a SendEmailRequest
and send it with Amazon SES on both the iOS and Android platforms.
SendEmailRequest request = new SendEmailRequest(email,destination,feedbackMessage);SendEmailResult result = clientManager.ses().sendEmail(request); |
A sample application that includes this code is provided in the AWS SDK for Android. The download link can be found on the following pages:
For more information about using AWS credentials with mobile applications see the following article:
Please feel free to ask questions or provide comments in the Mobile Development Forum.
On the occasion of our first birthday, we’d like to take this opportunity to thank our developer community. It’s been a busy year here at the Amazon Appstore for Android. Our store has grown tremendously since launching one year ago, and we could not have made it happen without partners like you. In our first year, customers have already bought millions of apps and games for their Kindle Fire and other Android devices. The Amazon Appstore has also grown its selection nearly eight-fold since launch, from 4,000 apps to over 31,000.
During our first year, we introduced Kindle Fire. Since launch, Kindle Fire has helped our developer community connect their apps with engaged customers. "At Quickoffice, we've experienced a massive lift in our Android app sales since the launch of Kindle Fire. The Amazon Appstore has been a great showcase for our app, and we've seen significant gains in conversion rates compared to other app stores based on the integrated Amazon buying experience," said Alan Masarek, CEO of Quickoffice, Inc.
Over the past year, we’ve been listening to your feedback, and we’re working on enhancing our tools and resources to meet your needs. We created blog posts to help your apps fly through testing, to help you message customers within your apps, and to help you develop for Kindle Fire. Over the last year, we released enhancements to our Developer Portal, including updated developer reports, and new user permissions functionally. And, we have more upgrades in the works for our second year of operations. We hope to support you with tools that allow you to continue delighting customers with your apps and games. In the coming weeks and months, check back here on our developer blog—we’ll be posting information on enhancements.
We know many of our developers are Amazon customers as well. To celebrate our first birthday, we worked with several of our developers to offer special discounts on some of our most popular apps. The Amazon Appstore Birthday event will get extra customer visibility from a dedicated Amazon Appstore Birthday page that will display new deals daily as well as more of customers’ favorite apps. The Amazon Appstore also kicks off its Amazon Appstore for Android Birthday Giveaway and will award a Kindle Fire to eight lucky winners who enter the sweepstakes by March 31st.
Thank you for your partnership! We look forward to collaborating with you to bring customers great apps for another year!
A few months ago, Amazon introduced Kindle Fire and, here on the blog, we talked about how you can get your app(s) onto Kindle Fire. We endeavor to provide our developers with useful, relevant information to help you develop your app(s) and we continue to get queries about developing for Kindle Fire. We have more information to share!
Your app requires an SD card—does Kindle Fire have one?
Kindle Fire has an internal SD card that your app can write to. Kindle Fire's SD card is internal and is not removable. You should not have to change your app for Kindle Fire if it currently stores data on the SD card. Using getExternalStorageDirectory() will enable you to write to the internal SD card on Kindle Fire.
Your app uses Adobe Air—will it work on Kindle Fire?
Yes, Adobe Air 2.7.1.1999 is pre-installed on Kindle Fire. If you wish to create and publish Adobe AIR 3 applications, you may do so by packaging them as 'captive runtime' apps. Note that captive runtime apps will not support on-device debugging.
Your app needs the support of an e-mail client—is that a feature of Kindle Fire?
Kindle Fire has a pre-installed e-mail client that will respond to both mailto links and e-mail intents.
How do you configure the supports-screens element for compatibility with Kindle Fire?
To ensure your app is compatible with Kindle Fire, specify <supports-screen android:largeScreens="true"/> in your manifest file.
Your app has audio—what audio playback does Kindle Fire support?
Kindle Fire supports the following audio formats natively:
You plan to upgrade your app to Android v4.x (Ice Cream Sandwich)—will your upgraded app work on Kindle Fire?
To increase the probability that your app will be compatible with Kindle Fire, you should only use Android 4.x APIs that are backwards compatible with Android 2.3 Gingerbread.
Your app has lots features—what specific features does Kindle Fire support?
Kindle Fire supports the features in the following list. To ensure your app is compatible with Kindle Fire, it should only use features found in this list.
A few months ago, Amazon introduced Kindle Fire and, here on the blog, we talked about how you can get your app(s) onto Kindle Fire. We endeavor to provide our developers with useful, relevant information to help you develop your app(s) and we continue to get queries about developing for Kindle Fire. We have more information to share!
Your app requires an SD card—does Kindle Fire have one?
Kindle Fire has an internal SD card that your app can write to. Kindle Fire's SD card is internal and is not removable. You should not have to change your app for Kindle Fire if it currently stores data on the SD card. Using getExternalStorageDirectory() will enable you to write to the internal SD card on Kindle Fire.
Your app uses Adobe Air—will it work on Kindle Fire?
Yes, Adobe Air 2.7.1.1999 is pre-installed on Kindle Fire. If you wish to create and publish Adobe AIR 3 applications, you may do so by packaging them as 'captive runtime' apps. Note that captive runtime apps will not support on-device debugging.
Your app needs the support of an e-mail client—is that a feature of Kindle Fire?
Kindle Fire has a pre-installed e-mail client that will respond to both mailto links and e-mail intents.
How do you configure the supports-screens element for compatibility with Kindle Fire?
To ensure your app is compatible with Kindle Fire, specify <supports-screen android:largeScreens="true"/> in your manifest file.
Your app has audio—what audio playback does Kindle Fire support?
Kindle Fire supports the following audio formats natively:
You plan to upgrade your app to Android v4.x (Ice Cream Sandwich)—will your upgraded app work on Kindle Fire?
To increase the probability that your app will be compatible with Kindle Fire, you should only use Android 4.x APIs that are backwards compatible with Android 2.3 Gingerbread.
Your app has lots features—what specific features does Kindle Fire support?
Kindle Fire supports the features in the following list. To ensure your app is compatible with Kindle Fire, it should only use features found in this list.
Note: Effective 08-26-2015 Free App of the Day (FAD) has been replaced with Amazon Underground.
Fire Maple Games is a mobile app developer located in Garnet Valley, PA. Their adventure game app, The Secret of Grisly Manor, continues to be a best-selling title since the launch of the Amazon Appstore for Android in March 2011. The sharp graphics and engaging storyline of this hidden object game continue to amass downloads and excellent reviews.
Fire Maple Games has taken advantage of many Amazon Appstore offerings including the Free App of the Day promotion. The Free App of the Day program has offered customers a paid app, for free, every day since the launch of the store. Additional, Fire Maple Games capitalized on app placement throughout the store and targeted e-mail campaigns. They also optimized their application for the Kindle Fire. By leveraging the Amazon Appstore platform, downloads of The Secret of Grisly Manor have seen significant gains on a weekly basis.
Initially engaged by the Free App of the Day promotion out of pure curiosity—what does and does not work when selling apps?—Fire Maple Games was pleased with the level of exposure they got from participating. “It was a fantastic increase of our user base,” said Joe Kauffman, owner of Fire Maple Games. “It wasn’t directly profitable, of course, as we were giving the game away for free, but now many more people have been exposed to the company and our games.” Kauffman has gotten many e-mails from people saying they would definitely buy the company’s next game. “For an indie developer on a limited budget, it was a great way to get the game into lots of people's hands,” he added.
Fire Maple Games joined the Amazon Appstore in November 2010 and was part of the Amazon Appstore launch four months later. “Amazon is such a great brand with such a powerful presence…we had high hopes for the Amazon Appstore for Android,” Kauffman said. They were also intrigued by the approval process and liked “that the apps would be curated, so a nicer selection of apps could be promoted.”
Fire Maple Games recently added a second adventure game, The Lost City, to their Amazon Appstore catalog, and the app has been getting stellar reviews. With the traction Fire Maple Games has seen thus far, new titles are sure to be a hit. “We use previous games to cross-sell new games,” Kauffman explained. “It seems to be working pretty well…both games have stayed within the Top 25!”
Kauffman revealed that the company hasn’t gotten any specific emails from customers regarding their experience with the Amazon Appstore and that that is a good thing: “It means that the process is pretty seamless. I recommend that everyone partner with Amazon! It is a nice, curated app-store with a great customer experience.”
Amazon is excited to announce an update to reports within the Amazon Appstore Developer Portal. Reports provide developers with important historical and trend data for sales and earnings. Improving the developer interface and strengthening service capability were two of the most important factors we focused on for this update.
During the past two months, we beta tested the update with more than 500 developers. Many of these developers provided valuable feedback that we incorporated into the final design.
Starting today, we will begin rolling out this update to all developers on the Amazon Appstore Developer Portal. You will notice the following changes:
We encourage developers to explore the new reports and provide feedback via the Contact Us link on the Amazon Appstore Developer Portal homepage or by clicking on the Submit Feedback flag on your Reports page.
January 26, 2012
Yosuke Matsuda
Amazon DynamoDB is a fast, highly scalable, highly available, cost-effective, non-relational database service. Amazon DynamoDB removes traditional scalability limitations on data storage while maintaining low latency and predictable performance. The sample mobile application described here demonstrates how to store user preferences in Amazon DynamoDB. Because more and more people are using multiple mobile devices, connecting these devices to the cloud, and storing user preferences in the cloud, enables developers to provide a more uniform cross-device experience for their users.
This article shows sample code for the Android platform. The complete sample code and project files are included in the AWS SDK for Android. Links to the SDK are available at the end of this article.
To use the sample app, you'll need to deploy a token vending machine (TVM). A TVM is a cloud-based application that manages AWS credentials for users of mobile applications. To deploy the TVM, you'll first need to obtain your own AWS credentials: an Access Key ID and Secret Key.
If you haven't already signed up for Amazon Web Services (AWS), you will need to do that first to get your AWS credentials. You can sign up for AWS here. After you sign up, you can retrieve your credentials at this page. The credentials will be used to set up the TVM to authenticate users of AWS mobile applications. Sample Java web applications are available here: Anonymous TVM and Identity TVM (this sample uses Anonymous TVM).
In Amazon DynamoDB, a database is a collection of tables. A table is a collection of items, and each item is a collection of attributes. For our app, we create a single table to store our list of users and their preferences. Each item in the table represents an individual user. Each item has multiple attributes, which include the user's name and their preferences. Each item also has a hash key—in this case, userNo
—which is the primary key for the table.
The app demonstrates how to add and remove users, and modify and retrieve their preference data. The app also demonstrates how to create and delete Amazon DynamoDB tables.
In order to create an Amazon DynamoDB client, we must first register the mobile device with the token vending machine (TVM). For this sample, we use the Anonymous TVM to register the device. Then we store the UID and key returned by the TVM on the device.
RegisterDeviceRequest registerDeviceRequest = new RegisterDeviceRequest(this.endpoint, this.useSSL, uid, key);ResponseHandler handler = new ResponseHandler();response = this.processRequest(registerDeviceRequest, handler);if (response.requestWasSuccessful()) { AmazonSharedPreferencesWrapper.registerDeviceId(this.sharedPreferences, uid, key);} |
The following code demonstrates how to request that the TVM generate temporary credentials, and how to store the returned credentials on the device.
Request getTokenRequest = new GetTokenRequest(this.endpoint, this.useSSL, uid, key);ResponseHandler handler = new GetTokenResponseHandler(key);GetTokenResponse getTokenResponse = (GetTokenResponse) this.processRequest(getTokenRequest, handler);if (getTokenResponse.requestWasSuccessful()) { AmazonSharedPreferencesWrapper.storeCredentialsInSharedPreferences( this.sharedPreferences, getTokenResponse.getAccessKey(), getTokenResponse.getSecretKey(), getTokenResponse.getSecurityToken(), getTokenResponse.getExpirationDate());} |
To make service requests to Amazon DynamoDB, you need to instantiate an Amazon DynamoDB client. The code below shows how to create an Amazon DynamoDB client for Android using the stored temporary credentials from the TVM.
AWSCredentials credentials = AmazonSharedPreferencesWrapper .getCredentialsFromSharedPreferences(this.sharedPreferences);AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(credentials); |
Each user's preferences are stored as items in an Amazon DynamoDB table. The following code creates that table using the client we created above. Every Amazon DynamoDB table require a hash key. In this sample, we use userNo
as the hash key for the table.
AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager.ddb();KeySchemaElement kse = new KeySchemaElement() .withAttributeName("userNo") .withAttributeType(ScalarAttributeType.N);KeySchema ks = new KeySchema().withHashKeyElement(kse);ProvisionedThroughput pt = new ProvisionedThroughput().withReadCapacityUnits(10l).withWriteCapacityUnits(5l);CreateTableRequest request = new CreateTableRequest() .withTableName(PropertyLoader.getInstance().getTestTableName()) .withKeySchema(ks) .withProvisionedThroughput(pt);ddb.createTable(request); |
Before we can move to the next step (creating users), we must wait until the status of the tables is ACTIVE. To retrieve the status of the table, we use a describe table request. This request returns information about the table such as the name of the table, item count, creation date and time, and its status.
AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager.ddb();DescribeTableRequest request = new DescribeTableRequest() .withTableName(PropertyLoader.getInstance().getTestTableName());DescribeTableResult result = ddb.describeTable(request);String status = result.getTable().getTableStatus(); |
For each user, we'll create an item in the table. An item is a collection of attribute/value pairs. For each item, we'll have three attributes: userNo
, firstName
, and lastName
. These are added to a put item request in order to create the item.
HashMap<String, AttributeValue> item = new HashMap<String, AttributeValue>();AttributeValue userNo = new AttributeValue().withN(String.valueOf(i));item.put("userNo", userNo);AttributeValue firstName = new AttributeValue().withS(Constants.getRandomName());item.put("firstName", firstName);AttributeValue lastName = new AttributeValue().withS(Constants.getRandomName());item.put("lastName", lastName);PutItemRequest request = new PutItemRequest().withTableName( PropertyLoader.getInstance().getTestTableName()).withItem(item);ddb.putItem(request); |
To remove a user from the list simply means deleting the corresponding item from the table. We specify the item we wish to delete using the hash key for the item.
AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager.ddb();Key primaryKey = new Key().withHashKeyElement(targetValue);DeleteItemRequest request = new DeleteItemRequest().withTableName( PropertyLoader.getInstance().getTestTableName()).withKey(primaryKey);ddb.deleteItem(request); |
We can retrieve a collection of users with a scan request. A scan request simply scans the table and returns the results in an undetermined order. Scan is an expensive operation and should be used with care to avoid disrupting your higher priority production traffic on the table. See the Amazon DynamoDB developer guide for more recommendations for safely using the Scan operation.
AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager.ddb();ScanRequest request = new ScanRequest();request.setTableName(PropertyLoader.getInstance().getTestTableName());ScanResult result = ddb.scan(request);ArrayList<HashMap<String, AttributeValue>> users = (ArrayList<HashMap<String, AttributeValue>>) result.getItems(); |
Knowing a user's userNo
, the hash key of the table, it is easy to find the item for the user. This next snippet shows how to get all the attributes for an item using the hash key.
AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager.ddb();AttributeValue userNoAttr = new AttributeValue().withN(String.valueOf(userNo));Key primaryKey = new Key().withHashKeyElement(userNoAttr);GetItemRequest request = new GetItemRequest().withTableName( PropertyLoader.getInstance().getTestTableName()).withKey(primaryKey);GetItemResult result = ddb.getItem(request);HashMap<String, AttributeValue> userPreferences = (HashMap<String, AttributeValue>) result.getItem(); |
The hash key also makes it easy to update an attribute for an item.
AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager.ddb();AttributeValue av = new AttributeValue().withS(value);AttributeValueUpdate avu = new AttributeValueUpdate().withValue(av).withAction(AttributeAction.PUT);Key primaryKey = new Key().withHashKeyElement(targetValue);HashMap<String, AttributeValueUpdate> updates = new HashMap<String, AttributeValueUpdate>();updates.put(key, avu);UpdateItemRequest request = new UpdateItemRequest() .withTableName(PropertyLoader.getInstance().getTestTableName()) .withKey(primaryKey).withAttributeUpdates(updates);ddb.updateItem(request); |
The easiest way to remove all the user preference data is to delete the Amazon DynamoDB table. The following code shows how:
AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager.ddb();DeleteTableRequest request = new DeleteTableRequest() .withTableName(PropertyLoader.getInstance().getTestTableName());ddb.deleteTable(request); |
The code in this article demonstrates how to use Amazon DynamoDB as a storage device for your mobile application. You can find more information about Amazon DynamoDB here.
Sample apps that include the code from this article are provided with the AWS SDK for Android. You can download the SDK using the following link:
For more information about using AWS credentials with mobile applications see the following article:
Authenticating Users of AWS Mobile Applications with a Token Vending Machine
Please feel free to ask questions or provide comments in the Mobile Development Forum.
Interested in learning more about selling your apps on Amazon.com and Kindle Fire? Aaron Rubenson, director of the Amazon Appstore for Android, will offer insight at CES into how developers can get in front of millions of Amazon customers – and make money – when they sell their apps at Amazon.com.
Learn about submitting apps for Kindle Fire, which topped Amazon.com’s “Best of 2011” list as the best-selling, most wished for, and most gifted product as determined by Amazon.com customers. Throughout December, customers purchased well over 1 million Kindle devices per week. Also on the agenda is information about programs such as in-app purchasing and Test Drive, which lets customers try an app on their computers before they buy.
Rubenson and other Amazon Appstore representatives will be available for informal discussions after the presentation.
Who: Aaron Rubenson, Director, Amazon Appstore for Android
What: “Selling Apps on Amazon.com and Kindle Fire”
Where: The Venetian Meeting Rooms, Veronese 2404
When: Friday, January 13, 9 a.m. – no R.S.V.P. needed
One great benefit to having your app on the Amazon Appstore for Android is cross-promotion. Cross-promotion is a form of marketing where customers of one product are targeted with promotion of a related product. Amazon.com has millions of customers, and those customers purchase tens of thousands of products every day. With so many great products (and customers), we have the unique ability to employ cross-promotion, even across product categories.
So, what do you need to do? Nothing! By default, apps that are published in the Amazon Appstore qualify to get picked up in the cross-merchandising widgets and promotions.
In the below image, you’ll see the product detail page for an Android app. In the Customers Who Bought Related Items Also Bought widget right below the general app information, you see that our site is automatically recommending a USB cable to the customer who is interested in this app—simply because other customers purchased similar items.
Similarly, in the following image, you can see the Customers Who Bought This Item Also Bought widget. This form of cross-promotion allows customers to make informed decisions about which apps they purchase while also showing them additional apps that might interest them.
Another Amazon widget that can benefit your app is the What Other Items Do Customers Buy After Viewing This Item? widget. Below, the widget is appearing on the product detail page for a tablet device and is advertising an app that was purchased by a customer who also purchased the tablet.
All of the above-mentioned widgets are automated, but we also have the ability to manually cross-promote your app. In the following image, note that on the product detail page for a hardcover copy of this Dr. Seuss book, we’ve added a recommendation for the related Android app.
Cross-promotion means customers can discover your app in a number of ways—not just by searching on the title or category. And over time, your app sales have the potential to increase, purely based on this cross-promotion. That’s never a bad thing, right?
December 16, 2011
gdierkes
![]() |
This article discusses how mobile apps can use Amazon Web Services to communicate with users via e-mail, short message service (SMS), and other communication channels. The sample code presented here uses Amazon Simple Notification Service and Amazon Simple Queue Service. Amazon Simple Notification Service (Amazon SNS) makes it easy to set up, manage, and send notifications from mobile apps and have these notifications delivered immediately to any users who have chosen to subscribe to them. Amazon SNS provides a highly scalable, flexible, and cost-effective method to implement such notification systems.
Amazon Simple Queue Service (Amazon SQS), also discussed here, offers a reliable, highly scalable, hosted queue for storing messages. The types of messages supported by Amazon SQS include—but aren't limited to—the notification messages sent from Amazon SNS.
Together, Amazon SNS and Amazon SQS enable developers to create apps that can message large numbers of users in multiple formats quickly and easily.
The sample app described here demostrates how mobile apps can message their users through Amazon SNS and Amazon SQS. The sample demonstrates how to use Amazon SNS to create a topic, subscribe users to that topic, and publish notifications to the topic. Subscribers to the topic can receive their notifications via e-mail, SMS, or an Amazon SQS queue. Amazon SQS and Amazon SNS can also be used to create other types of communication systems not shown here.
This article shows sample code but the complete sample code and project files are included in the AWS SDK for Android. A link to the SDK is available at the end of this article.
To use the AWS SDK for Android, you will need AWS credentials, that is, an Access Key ID and Secret Access Key. If you haven't already signed up for Amazon Web Services (AWS), you will need to do that first to get your credentials. You can sign up for AWS here. After you sign up, you can retrieve your credentials at this page.
Making requests to Amazon SNS and Amazon SQS requires creating a client for each service. The code below shows how to create a client:
AWSCredentials credentials = new BasicAWSCredentials( Constants.ACCESS_KEY_ID, Constants.SECRET_KEY ); AmazonSNSClient snsClient = new AmazonSNSClient( credentials );AmazonSQSClient sqsClient = new AmazonSQSClient( credentials ); |
Amazon SNS uses topics to route notifications from publishers to subscribers. The term publisher refers to an app that sends notifications; the term subscriber refers to an entity, such as a user, that receives notifications. Topics provide a junction point for publishers and subscribers to communicate with each other. Once a topic is created, subscribers can be added to the topic and receive notifications/messages. The DisplayName attribute is added to a topic to allow notifications to be sent via SMS.
CreateTopicRequest ctr = new CreateTopicRequest( Constants.TOPIC_NAME );CreateTopicResult result = snsClient.createTopic( ctr ); SetTopicAttributesRequest tar = new SetTopicAttributesRequest( result.getTopicArn(), "DisplayName", "MessageBoard" );this.snsClient.setTopicAttributes( tar ); |
In order for notifications sent to a topic to be received, you have to subscribe an endpoint to that topic. The endpoint corresponds to a recipient. An endpoint is an e-mail address, SMS number, web server, or Amazon SQS queue. If you are using an Amazon SQS queue, it needs to be configured to receive notification messages from Amazon SNS. Once you subscribe an endpoint to a topic and the subscription is confirmed, the endpoint will receive all messages published to that topic.
SubscribeRequest sr = new SubscribeRequest( this.topicARN, "email", email );this.snsClient.subscribe( sr ); |
Listing the subscribers for a topic provides the endpoint and corresponding protocol for each subscriber who receives notification via that topic. The protocol for an endpoint depends on the type of endpoint. For example, endpoints that are e-mail addresses have a protocol of SMTP.
ListSubscriptionsByTopicRequest ls = new ListSubscriptionsByTopicRequest( this.topicARN );ListSubscriptionsByTopicResult response = this.snsClient.listSubscriptionsByTopic( ls );return response.getSubscriptions(); |
Publishers send notifications to topics. Once a new notification is published, Amazon SNS attempts to deliver that notification to every endpoint that is subscribed to the topic.
PublishRequest pr = new PublishRequest( this.topicARN, message );this.snsClient.publish( pr ); |
Unsubscribing removes the endpoint from the topic and stops notifications from being received.
UnsubscribeRequest unsubscribeRequest = new UnsubscribeRequest( subscriptionArn );this.snsClient.unsubscribe( unsubscribeRequest ); |
The first task in using Amazon SQS is to create a queue. Once a queue is created it can be subscribed as an endpoint to an Amazon SNS topic.
CreateQueueRequest cqr = new CreateQueueRequest( Constants.QUEUE_NAME );CreateQueueResult result = this.sqsClient.createQueue( cqr );return result.getQueueUrl(); |
Here's how to subscribe a queue to a topic. However, for the queue to receive messages, you must also add a policy to the queue. See below.
String queueArn = this.createMessageQueue(); SubscribeRequest request = new SubscribeRequest();request.withEndpoint( queueArn ).withProtocol( "sqs" ).withTopicArn( this.topicARN ); this.snsClient.subscribe( request ); |
In order for a queue to receive messages from a topic, the queue must have a policy object that specifies that the topic has sqs:SendMessage permission for the queue. For further details see the Amazon SNS FAQ. For more information about queue policies see the Amazon SQS documentation. Once the policy object is created it can be attached to the queue as follows:
HashMap attributes = new HashMap();attributes.put("Policy", generateSqsPolicyForTopic( queueArn, this.topicARN ) );this.sqsClient.setQueueAttributes(new SetQueueAttributesRequest( queueUrl, attributes ) ); |
Now that a message is in the queue, you can receive it, which requires getting it from the queue. When requesting to get a message from the queue, you can't specify which message to get. Instead, you simply specify the maximum number of messages you want to get (up to 10), and Amazon SQS returns up to that maximum number. Because Amazon SQS is a distributed system and the particular queue we're working with here has very few messages in it, the response to the receive request might be empty. Therefore, you should rerun the sample until you get the message. You should design your own app so that it continues to poll the queue until it gets one or more messages.
ReceiveMessageRequest rmr = new ReceiveMessageRequest( this.queueUrl );rmr.setMaxNumberOfMessages( 10 );rmr.setVisibilityTimeout( 30 );ReceiveMessageResult result = this.sqsClient.receiveMessage( rmr ); |
Amazon SQS doesn't automatically delete a message after returning it to the app. By default, it keeps the message to protect against the case where the receiving app fails or loses its connection. In these cases, a different app—or perhaps a new instance of the same app— might attempt to get the message.
To delete the message, you must send a separate request. You specify which message to delete by providing the receipt handle that Amazon SQS returned when you received the message. You can delete only one message per call. Deleting the message acknowledges that you've successfully received and processed it.
DeleteMessageRequest request = new DeleteMessageRequest( this.queueUrl, message.getReceiptHandle() );this.sqsClient.deleteMessage( request ); |
A sample app that includes this code is provided with the SDK. The download link can be found on the following page:
For more information about using AWS credentials with mobile apps see the following article:
Please feel free to ask questions or provide comments in the Mobile Development Forum.
November 30, 2011
gdierkes
This article highlights the benefits of connecting mobile devices to the cloud while also presenting an Amazon SimpleDB use case. Amazon SimpleDB is a highly available, flexible, and scalable non-relational data store that offloads the work of database administration. The app described here demonstrates how to store a high score list or leader board in SimpleDB. The app enables the user to view the high scores sorted by name or score, add and remove scores, and more. This article shows sample code for the Android platform. The complete sample code and project files are included in the AWS SDK for Android. A link to the SDK is available at the end of this article.
To use the AWS SDK for Android, you will need your AWS credentials, that is, your Access Key ID and Secret Access Key. If you haven't already signed up for Amazon Web Services (AWS), you will need to do that first to get your AWS credentials. You can sign up for AWS here. After you have signed up, you can retrieve your credentials at this page.
SimpleDB stores data in domains. Each domain is a collection of items and each item is a collection of attribute/value pairs. For the app, we create a single domain to store our high score list. Each item in the domain represents an individual player. The items will have two attributes, the player's name and their score. Items also have a unique identifier called the item name that, in this case, is equal to the player's name. Storing the player's name and score as item attributes enables us to sort the items by name or score.
The app demonstrates how to add and remove individual players, sort the scores by player name or score, and retrieve a single item from the domain. The app also demonstrates how to create and delete SimpleDB domains.
Making requests to SimpleDB requires a client. Creating a SimpleDB client for Android is shown below.
AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY_ID, SECRET_KEY);AmazonSimpleDBClient sdbClient = new AmazonSimpleDBClient( credentials); |
Individual player scores are stored as items in a SimpleDB domain. This requires that we create the domain first. Using the appropriate client that we created above, we can use the following code to create the domain.
CreateDomainRequest cdr = new CreateDomainRequest( HIGH_SCORES_DOMAIN );sdbClient.createDomain( cdr ); |
An item is a collection of attribute/value pairs. For our items, we create two attributes, one for the player's name and one for the player's score. These are added to a request along with an item name in order to create the item. Because a player appears at most only once on the high score list, we use the player's name to uniquely identify each item. All data in SimpleDB are stored as strings, therefore numbers must be zero padded if you want to sort them properly. The AWS SDK for Android includes a utility to pad numbers, used below.
String paddedScore = SimpleDBUtils.encodeZeroPadding( score, 10 ); ReplaceableAttribute playerAttribute = new ReplaceableAttribute(PLAYER_ATTRIBUTE, player, Boolean.TRUE);ReplaceableAttribute scoreAttribute = new ReplaceableAttribute(SCORE_ATTRIBUTE, paddedScore, Boolean.TRUE); List attrs = new ArrayList(2);attrs.add( playerAttribute );attrs.add( scoreAttribute ); PutAttributesRequest par = new PutAttributesRequest(HIGH_SCORES_DOMAIN, player, attrs); sdbClient.putAttributes( par ); |
Removing a score from the list simply means deleting an item from the domain. Deleting an item requires the unique name for the item you wish to delete. In SimpleDB, deleting an item is done by removing all the attributes from that item. Invoking deleteAttributes with no specified attributes removes all the attributes by default.
DeleteAttributesRequest dar = new DeleteAttributesRequest( HIGH_SCORES_DOMAIN, player );sdbClient.deleteAttributes( dar ); |
Knowing an item's name makes it easy to find the item. This next snippet shows how to get all the attributes for an item using the item name. Note that items may contain many attributes and values.
GetAttributesRequest gar = new GetAttributesRequest( HIGH_SCORES_DOMAIN, player );GetAttributesResult response = sdbClient.getAttributes(gar); |
Getting a collection of scores, sorted by player name or the score itself requires the use of a select request. A select request uses a simple query language to determine which items to match and what data to return and how. Select requests are paginated because the number of items matching the query can be large. Therefore, select requests return a next token that enables you to "page" through the data in an ordered fashion. The code here shows how to return items ordered by score from highest to lowest. Only the score and player attributes are returned. More information regarding SimpleDB queries can be found in a reference article linked below.
String select = "select player, score from HighScores where score >= '0' order by score desc";SelectRequest selectRequest = new SelectRequest( select ).withConsistentRead( true );selectRequest.setNextToken( nextToken ); SelectResult response = sdbClient.select( selectRequest );nextToken = response.getNextToken(); |
The quickest and easiest way to remove the entire high score list would be to delete the SimpleDB domain. Here is how to do that.
DeleteDomainRequest ddr = new DeleteDomainRequest( HIGH_SCORES_DOMAIN );sdbClient.deleteDomain(ddr); |
The code in this article demonstrates how to use Amazon SimpleDB as an indexed storage device for your app. The complete sample app is included as part of the AWS mobile SDKs, which are linked below. The reference section also contains a link to a SimpleDB article which discusses writing queries for SimpleDB in detail.
Find more information about SimpleDB here.
A sample app that includes this code is provided with the AWS SDK for Android
For more information about using AWS credentials with apps see the article, Authenticating Users of AWS Mobile Applications with a Token Vending Machine
Please feel free to ask questions or provide comments in the Mobile Development Forum.
Recently Amazon released Kindle Fire, our newest addition to the Kindle family that showcases a color touch display and provides instant access to the Amazon Appstore for Android and Amazon’s massive selection of digital content, as well as free storage in the Amazon Cloud.
Kindle Fire puts Amazon’s digital powerhouse of content at customers’ fingertips. In addition to the thousands of popular apps and games available in the Amazon Appstore for Android, customers can also choose from over 18 million movies, TV shows, songs, magazines, and books—and all of their Amazon content is automatically stored in the Amazon cloud, free of charge. Web browsing is simple and fast with Amazon Silk and an even better experience because of the Kindle Fire’s vibrant color touchscreen with an extra-wide viewing angle. All this, plus a fast, powerful dual-core processor, and an unbeatable price, make us proud of this newest member of our Kindle family.
Don’t take our word on it though—we’re not the only ones admiring Kindle Fire!
The first easy-to-use, affordable small-screen tablet, the Amazon Kindle Fire is revolutionary...I can't emphasize this "ease of use" thing enough. More than anything else, that's what's been holding non-iPad tablets back. Amazon cracked it. End of story." - PC Mag
"The Kindle Fire is a 7-inch tablet that links seamlessly with Amazon's impressive collection of digital music, video, magazine, and book services in one easy-to-use package. It boasts a great Web browser, and its curated Android app store includes most of the big must-have apps (such as Netflix, Pandora, and Hulu). The Fire has an ultra-affordable price tag, and the screen quality is exceptional for the price." – CNET
How do you get your app onto the Kindle Fire?
Submit it! Simply join the Amazon Appstore Developer Program, if you haven’t already, and submit your app using the Amazon Appstore Developer Portal just as you would if you were submitting to our store for any other supported Android device. All apps will go through regular Amazon Appstore testing, as well as testing for Kindle Fire.
What are the requirements for your app to work on Kindle Fire?
For your app to work on Kindle Fire, it needs to be compatible with the device's specifications. At a high level, it must be optimized for non-Google Mobile Services (GMS), Android 2.3.4 (Gingerbread), and a 7" screen with a resolution of 1024 x 600. Your app cannot require a gyroscope, camera, WAN module, Bluetooth, microphone, GPS, or micro-SD to function. In addition, your app must not be a theme or wallpaper that manipulates the user interface of the device. As with any other app submission to the Amazon Appstore for Android, your app will also need to comply with our Content Guidelines. For additional information, please visit our Kindle Fire FAQs.
What if your app was already submitted - will it be considered?
Yes. If you already have an app published in the Amazon Appstore for Android, we will automatically review the app for Kindle Fire compatibility. We're currently in the process of testing our entire catalog of published apps to ensure each app provides a high-quality customer experience on Kindle Fire.
What if you want to test your app(s) prior to submitting?
We strongly recommend you test your app on your own and submit an update if you discover any problems. It is possible to configure a standard Android emulator to simulate the Kindle Fire device platform. You should configure your emulator with the following characteristics:
If you haven’t already submitted your apps, submit via the Amazon Appstore Developer Portal. Interested in marketing opportunities? Fill out our marketing request form.
November 14, 2011
amberta
Kindle Fire ships today, and we think this is a huge win for Amazon.com customers and Amazon Appstore for Android developers. As we mentioned in a Kindle Fire announcement blog post, Kindle Fire boasts Amazon’s incredible selection of digital content at customers’ fingertips:
For Amazon Appstore developers, Kindle Fire offers another venue for getting your apps in front of potential customers. You’ll start seeing Kindle Fire, and apps that were Amazon-tested on Kindle Fire for the best experience possible, sprinkled throughout Amazon.com and in the Amazon Appstore marketing campaigns, in addition to the placements where we’ve already been showcasing apps. You can view a selection of some of our favorite Kindle Fire apps in the Amazon Appstore here.
Some of the titles you may have seen in recent press include Netflix, Rhapsody, Pandora, Comics by comiXology, Facebook, The Weather Channel and popular games from Zynga, EA, Gameloft, PopCap, and Rovio. Thousands of the Amazon Appstore editorial team’s favorites, such as Bird’s the Word, Pinball Deluxe, SketchBook Mobile, Super Sudoku, X Construction, Monkey Preschool Lunchbox, and more are available as well.
What does this mean for you?
As always, we encourage you to ensure you have submitted the most current versions of all your apps to the Amazon Appstore for Android. Now is also a good time to verify that each app’s meta-data (including list price) is up-to to-date. You can update your existing apps and submit new apps using the Amazon Appstore Developer Portal.
Where can you find the technical specifications for Kindle Fire?
The Kindle Fire has a 7” multi-touch display with 1024 x 600 pixel resolution at 169 ppi, can display 16 million colors, and has instant access to the Amazon Appstore for Android. For more detailed information about the device, including technical specifications, app compatibility information, development tips, and instructions for submitting your app, please see our Kindle Fire FAQ.
You can order a Kindle Fire to test your apps online at amazon.com/kindlefire.
How can developers get merchandising placement in the Amazon Appstore and on Kindle Fire?
If you have ideas about merchandising and marketing your app at the Amazon Appstore, or if you would like to be considered for Free App of the Day placement, please fill out the Marketing Proposal Form.
This article demonstrates how to use the AWS SDK for Android to uploadan image to Amazon Simple StorageService (S3) from your mobile device and how to make that imageavailable on the web. Amazon S3 is storage for the Internet. It's a simplestorage service that offers software developers a highly-scalable,reliable, secure, fast, and inexpensive data storage. The complete samplecode and project files are included in the AWS SDK for Android which canbe found here.
To use the AWS SDK for Android, you will need your AWS credentials,that is, your Access Key ID and Secret Access Key. If you haven'talready signed up for Amazon WebServices (AWS), you will need to do that first to get your AWScredentials. You can sign up for AWS here.
Here's what the sample app looks like at start up on Android:
The app uses each platform's "image picker" utility to have theend-user select an image for upload. The app then creates an Amazon S3client, uses the client to create an Amazon S3 bucket in which to storethe image, and finally uploads the image into the bucket. A bucket is acontainer for objects stored in Amazon S3. Every object--such as animage--is contained within a bucket.
The first step is to retrieve the content, in this case an image, tobe uploaded to Amazon S3. For this sample app, selecting an image from thedevice itself is an easy choice.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);intent.setType("image/*");startActivityForResult(intent, PHOTO_SELECTED);
Once an image is selected, a callback method is invoked with theselected image's information. The app uses this information to completethe upload.
Once we have the image, we can attempt to upload it to Amazon S3.
First, create an Amazon S3 client to communicate withthe service.
AmazonS3Client s3Client = new AmazonS3Client( new BasicAWSCredentials( MY_ACCESS_KEY_ID, MY_SECRET_KEY ) );
Second, create an Amazon S3 bucket to store thepicture.
s3Client.createBucket( MY_PICTURE_BUCKET );
Finally, put the image object into the Amazon S3bucket.
PutObjectRequest por = new PutObjectRequest( Constants.getPictureBucket(), Constants.PICTURE_NAME, new java.io.File( filePath) );s3Client.putObject( por );
The app makes the image available for viewing in a browser bygenerating a pre-signed URL. A pre-signed URL is a URL for an Amazon S3resource that is signed with current AWS security credentials. Thepre-signed URL can then be shared with other users, allowing them toaccess resources without providing an account's AWS securitycredentials.
First, create an override content type to ensure thatthe "content" will be treated as an image by the browser.
ResponseHeaderOverrides override = new ResponseHeaderOverrides();override.setContentType( "image/jpeg" );
Second, create the pre-signed URL request. Pre-signedURLs can be created with an expiration date, that is, a date andtime after which the resource will no longer be available. In the sample,the pre-signed URLs are valid for only one hour.
GeneratePresignedUrlRequest urlRequest = new GeneratePresignedUrlRequest( Constants.getPictureBucket(), Constants.PICTURE_NAME );// Added an hour's worth of milliseconds to the current time.urlRequest.setExpiration( new Date( System.currentTimeMillis() + 3600000 ) );urlRequest.setResponseHeaders( override );
Third, generate the pre-signed URL.
URL url = s3Client.generatePresignedUrl( urlRequest );
Finally, launch the browser to view the pre-signed URLwhich will display the image.
startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse( url.toURI().toString() ) ));
These few lines of code demonstrate how Amazon S3 could become alimitless storage device for your mobile photos. A photo sharing app thatallows users to view photos from other users would not be a difficultextension to the above code. Also, the content that is uploaded and sharedis not limited to images. The content could be audio files, video files,text, or other content that users want to store and share.
A sample app that includes this code is provided with both mobile SDKs.The download links can be found here: AWS SDK for Android.
For more information about using AWS credentials with mobileapplications see the following article: Authenticating Users of AWS Mobile Applications with a Token VendingMachine
Please feel free to ask questions or make comments in the MobileDevelopment Forum.
Portions of this page are reproduced from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.
November 08, 2011
johnjord
Recently, the Amazon Appstore for Android featured Read It Later Pro as the Free App of the Day. The extremely popular and useful application allows users to save what they find on the web to watch and read on any device and at any time – a “DVR for the web,” states The New York Times.
Founded in 2007, the company already boasts 3.5 million users and sees millions of articles saved each week through their very user-friendly and seamless service.
Also, the company “runs the entire Read It Later operation on Amazon Web Services [AWS],” states founder Nate Weiner. “We take advantage of EC2 for our servers, ELB for load balancing, S3 and EBS for storage. We also use Amazon Simple Email Services [SES], which has simplified our e-mail communications and made them more effective.” Although very excited about the Free App of the Day promotion, the Read It Later team expressed some concern over the large number of expected new customers and the impact on their 50K daily e-mail limit through SES.
According to Read It Later CTO and Engineer Matt Koidin, the internal teams at Amazon moved quickly to address a solution for this use case. “We initially thought we would need additional development to work around the e-mail limit… but our account manager was able to coordinate with the AWS team to increase the limit for the day,” Koidin said.
Koidin and team see this as another example of the Amazon Appstore’s ability to provide an advantage through its network of services for developers. “Having Amazon not only run the promotion, but work with the broader Amazon organization (i.e. AWS) to provide some assistance so it didn’t overwhelm us or require additional work, shows they are aligned as a partner to make this a success for everyone involved,” added Koidin.
The team at Read It Later was happy to report that the promotion resulted in “one of our largest days of new user acquisition ever” and “we’ve seen our transaction level sustain at a higher level than prior to the promotion.” They see more exciting opportunities down the road to incorporate additional Amazon services for developers. When asked if they would run the Free App of the Day promotion again, Koidin replied with a simple, “Absolutely.”
Learn more about AWS online here.