Drop-in auth
The AWSMobileClient
client supports a simple "drop-in" UI for your application. You can add drop-in Auth UI like so:
1// 'this' refers the current active activity2AWSMobileClient.getInstance().showSignIn(this, new Callback<UserStateDetails>() {3 @Override4 public void onResult(UserStateDetails result) {5 Log.d(TAG, "onResult: " + result.getUserState());6 }7
8 @Override9 public void onError(Exception e) {10 Log.e(TAG, "onError: ", e);11 }12});
In the above code you would have created an Android Activity called NextActivity
which would automatically be navigated to upon successful sign-up and sign-in. For testing, you can alternatively just use MainActivity.class
after initializing:
1AWSMobileClient.getInstance().showSignIn(2 this,3 SignInUIOptions.builder()4 .nextActivity(NextActivity.class)5 .build(),6 new Callback<UserStateDetails>() {7 @Override8 public void onResult(UserStateDetails result) {9 Log.d(TAG, "onResult: " + result.getUserState());10 switch (result.getUserState()){11 case SIGNED_IN:12 Log.i("INIT", "logged in!");13 break;14 case SIGNED_OUT:15 Log.i(TAG, "onResult: User did not choose to sign-in");16 break;17 default:18 AWSMobileClient.getInstance().signOut();19 break;20 }21 }22
23 @Override24 public void onError(Exception e) {25 Log.e(TAG, "onError: ", e);26 }27 }28);
The above code also shows an additional Auth API, signOut()
. For more advanced scenarios, you can call the AWSMobileClient
APIs, such as for building your own UI or using functionality in different UX of your application lifecycle.
Customization
Currently, you can change the following properties of the drop-in UI with the AWSMobileClient
:
- Logo: Any Drawable resource supported by ImageView
- Background Color: Any color Android supported
1AWSMobileClient.getInstance().showSignIn(2 this,3 SignInUIOptions.builder()4 .nextActivity(NextActivity.class)5 .logo(R.id.logo)6 .backgroundColor(R.color.black)7 .canCancel(false)8 .build(),9 new Callback<UserStateDetails>() {10 @Override11 public void onResult(UserStateDetails result) {12 Log.d(TAG, "onResult: " + result.getUserState());13 }14
15 @Override16 public void onError(Exception e) {17 Log.e(TAG, "onError: ", e);18 }19 }20);
You can allow the sign in process to be dismissed by setting the canCancel
property.