Amazon provides AWS Mobile SDK with JAVA APIs for various Amazon Services (including Amazon Cognito, AWS Lambda, Amazon S3, Amazon Kinesis, Amazon DynamoDB, Amazon Pinpoint…) so that we can build high quality mobile apps quickly and easily. In this tutorial, we’re gonna look at how to integrate AWS Mobile SDK into an Android App.
Contents
I. Technology
– Android Studio 2.x
– AWS Mobile SDK Client 2.6.7
II. Step by Step
1. Set Up Backend
1.1 Sign up for the AWS Free Tier
Go to https://aws.amazon.com/free/
:
Choose Create a free Account.
Follow the instructions on the screen for sign up.
-> AWS will notify you by email when your account is active and available for you to use.
1.2 Create a Mobile Hub project
– Go to https://console.aws.amazon.com/mobilehub/
, then click on Create button:
– Enter project name, then click on Next:
– Select Platform, then click on Add:
– Download Cloud Config file (awsconfiguration.json) to your PC:
After finishing these step, you can see your project in Amazon Console – Mobile Hub:
2. Connect to Backend
2.1 Add Cloud Config file
Place awsconfiguration.json file in app/src/main/res/raw:
2.2 Set permission
Open AndroidManifest.xml, add:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.javasampleapproach.s3amazon"> <application ...> ... </application> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> </manifest> |
2.3 Add dependencies
These libraries enable basic AWS functions, like credentials, and analytics. Open app/build.gradle, add:
dependencies { ... implementation ('com.amazonaws:aws-android-sdk-mobile-client:2.6.7@aar') { transitive = true } } |
2.4 Establish a connection with AWS Mobile
In main or startup activity, add code to onCreate
method:
import com.amazonaws.mobile.client.AWSMobileClient; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AWSMobileClient.getInstance().initialize(this).execute(); } } |
Now your app can interact with the AWS services.
Run App in Android Studio, you should see log in Android logcat:
com.javasampleapproach.s3amazon I/AWSMobileClient: Welcome to AWS! You are connected successfully. com.javasampleapproach.s3amazon D/AWSMobileClient: AWSMobileClient Initialize succeeded. |
Last updated on July 13, 2018.
Hello Sir
This is Aravind, after finishing my integration in logcat i saw
“/com.nnk.imageintos3 I/OPenGLRenderer: Initialized EGL, version 1.4”
Is this Integrated or not?
Actually if SDK integrated successfully will see
“/com.nnk.imageintos3 I/OpenGLRender: Initialized Successed”
please solve my Issue
Thank you