@@ -91,14 +91,15 @@ Twitter app as reported by the [Twitter application manager](https://apps.twitte
91
91
</resources>
92
92
```
93
93
94
- In addition, if are using Smart Lock or require a user's email, you must enable the
94
+ In addition, if you are using Smart Lock or require a user's email, you must enable the
95
95
"Request email addresses from users" permission in the "Permissions" tab of your app.
96
96
97
97
## Using FirebaseUI for Authentication
98
98
99
99
Before invoking the FirebaseUI authentication flow, your app should check
100
100
whether a
101
- [ user is already signed in] ( https://firebase.google.com/docs/auth/android/manage-users#get_the_currently_signed-in_user ) from a previous session:
101
+ [ user is already signed in] ( https://firebase.google.com/docs/auth/android/manage-users#get_the_currently_signed-in_user )
102
+ from a previous session:
102
103
103
104
``` java
104
105
FirebaseAuth auth = FirebaseAuth . getInstance();
@@ -141,12 +142,22 @@ If no customization is required, and only email authentication is required, the
141
142
can be started as follows:
142
143
143
144
``` java
145
+ // Choose an arbitrary request code value
146
+ private static final int RC_SIGN_IN = 123 ;
147
+
148
+ // ...
149
+
144
150
startActivityForResult(
145
151
// Get an instance of AuthUI based on the default app
146
152
AuthUI . getInstance(). createSignInIntentBuilder(). build(),
147
153
RC_SIGN_IN );
148
154
```
149
155
156
+ To kick off the FirebaseUI sign in flow, call startActivityForResult(...) on the sign in Intent you built.
157
+ The second parameter (RC_SIGN_IN) is a request code you define to identify the request when the result
158
+ is returned to your app in onActivityResult(...). See the [ response codes] ( #response-codes ) section below for more
159
+ details on receiving the results of the sign in flow.
160
+
150
161
You can enable sign-in providers like Google Sign-In or Facebook Log In by calling the
151
162
` setProviders ` method:
152
163
@@ -216,28 +227,31 @@ supported.
216
227
``` java
217
228
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
218
229
super . onActivityResult(requestCode, resultCode, data);
219
- if (resultCode == RESULT_OK ) {
220
- // user is signed in!
221
- startActivity(new Intent (this , WelcomeBackActivity . class));
222
- finish();
223
- return ;
224
- }
225
-
226
- // Sign in canceled
227
- if (resultCode == RESULT_CANCELED ) {
228
- showSnackbar(R . string. sign_in_cancelled);
229
- return ;
230
- }
231
-
232
- // No network
233
- if (resultCode == ResultCodes . RESULT_NO_NETWORK ) {
234
- showSnackbar(R . string. no_internet_connection);
235
- return ;
230
+ // RC_SIGN_IN is the request code you passed into startActivityForResult(...) when starting the sign in flow
231
+ if (requestCode == RC_SIGN_IN ) {
232
+ if (resultCode == RESULT_OK ) {
233
+ // user is signed in!
234
+ startActivity(new Intent (this , WelcomeBackActivity . class));
235
+ finish();
236
+ return ;
237
+ }
238
+
239
+ // Sign in canceled
240
+ if (resultCode == RESULT_CANCELED ) {
241
+ showSnackbar(R . string. sign_in_cancelled);
242
+ return ;
243
+ }
244
+
245
+ // No network
246
+ if (resultCode == ResultCodes . RESULT_NO_NETWORK ) {
247
+ showSnackbar(R . string. no_internet_connection);
248
+ return ;
249
+ }
250
+
251
+ // User is not signed in. Maybe just wait for the user to press
252
+ // "sign in" again, or show a message.
236
253
}
237
-
238
- // User is not signed in. Maybe just wait for the user to press
239
- // "sign in" again, or show a message.
240
- }
254
+ }
241
255
```
242
256
243
257
Alternatively, you can register a listener for authentication state changes;
0 commit comments