- Newest
- Most votes
- Most comments
To migrate from AWS Mobile SDK to Amplify SDK for Android, you'll need to adapt your custom authentication approach to work with Amplify's storage capabilities. Here's how you can approach this migration:
First, you'll need to add the necessary Amplify dependencies to your Android project. In your app's build.gradle file, you should include both the Amplify core libraries and the specific modules for authentication and storage:
dependencies {
// Amplify core
implementation 'com.amplifyframework:aws-auth-cognito:x.x.x'
implementation 'com.amplifyframework:aws-storage-s3:x.x.x'
}
The aws-auth-cognito library is specifically required to provide authentication for Amazon S3 operations.
For your custom authentication scenario where you're retrieving identity IDs and tokens from your backend service, you'll need to implement a custom authentication plugin for Amplify. This would replace your current custom implementation of AWSAbstractCognitoDeveloperIdentityProvider.
After configuring the authentication, you can initialize Amplify in your application class:
Amplify.addPlugin(new AWSCognitoAuthPlugin()); Amplify.addPlugin(new AWSS3StoragePlugin()); Amplify.configure(getApplicationContext());
Then, you can use Amplify's Storage API to upload and download files, which will replace your current usage of TransferUtility:
// Upload example Amplify.Storage.uploadFile( "example.txt", new File("/path/to/file"), result -> Log.i("MyApp", "Upload succeeded"), error -> Log.e("MyApp", "Upload failed", error) ); // Download example Amplify.Storage.downloadFile( "example.txt", new File("/path/to/download/location"), result -> Log.i("MyApp", "Download succeeded"), error -> Log.e("MyApp", "Download failed", error) );
Note that with Amplify, users must be signed in or you must configure guest access before using storage features. Since you're retrieving authentication tokens from your backend, you'll need to ensure these are properly integrated with Amplify's authentication system.
AWS Amplify is the recommended path forward for developing new cloud-connected Android apps, as the AWS Mobile SDK is no longer being updated or supported with new features.
Sources
AWS Mobile for Android and iOS - AWS Mobile Hub
Set up Storage - Android - AWS Amplify Gen 2 Documentation
Relevant content
- asked 3 years ago
- asked 3 years ago
