本文整理汇总了Java中com.google.firebase.auth.UserInfo类的典型用法代码示例。如果您正苦于以下问题:Java UserInfo类的具体用法?Java UserInfo怎么用?Java UserInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserInfo类属于com.google.firebase.auth包,在下文中一共展示了UserInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signOut
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
public static void signOut(GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
DatabaseHelper.getInstance(fragmentActivity.getApplicationContext())
.removeRegistrationToken(FirebaseInstanceId.getInstance().getToken(), user.getUid());
for (UserInfo profile : user.getProviderData()) {
String providerId = profile.getProviderId();
logoutByProvider(providerId, mGoogleApiClient, fragmentActivity);
}
logoutFirebase(fragmentActivity.getApplicationContext());
}
if (clearImageCacheAsyncTask == null) {
clearImageCacheAsyncTask = new ClearImageCacheAsyncTask(fragmentActivity.getApplicationContext());
clearImageCacheAsyncTask.execute();
}
}
示例2: getProviderData
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
private void getProviderData() {
// [START get_provider_data]
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
for (UserInfo profile : user.getProviderData()) {
// Id of the provider (ex: google.com)
String providerId = profile.getProviderId();
// UID specific to the provider
String uid = profile.getUid();
// Name, email address, and profile photo Url
String name = profile.getDisplayName();
String email = profile.getEmail();
Uri photoUrl = profile.getPhotoUrl();
};
}
// [END get_provider_data]
}
示例3: syncUserProfiles
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
private void syncUserProfiles() {
String uid = mFirebaseUser.getUid();
final DatabaseReference user = mDatabase.getReference("/users").child(uid);
user.child("email").setValue(mFirebaseUser.getEmail());
user.child("name").setValue(mFirebaseUser.getDisplayName());
setDisplayName(mFirebaseUser.getDisplayName());
for (UserInfo userInfo : mFirebaseUser.getProviderData()) {
if (!userInfo.getProviderId().equals("firebase")) {
user.child(userInfo.getProviderId().split("\\.")[0]).setValue(userInfo.getUid());
}
}
// if (isUsingInstagram()) {
// if (instagramEngine == null) {
// setupInstagram();
// }
// instagramEngine.getUserDetails(new InstagramUserIdCallback(user));
// }
}
示例4: saveUserInfo
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
@Override
public void saveUserInfo() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
String id = "";
String name = user.getDisplayName();
String email = user.getEmail();
String photoUrl = user.getPhotoUrl().toString();
for (UserInfo profile : user.getProviderData()) {
String providerId = profile.getProviderId();
if (providerId.compareToIgnoreCase("facebook.com") == 0) {
id = profile.getUid();
break;
}
}
userInfo.put(USERINFO.ID, id);
userInfo.put(USERINFO.FIRSTNAME, name.split(" ")[0]);
userInfo.put(USERINFO.FULLNAME, name);
userInfo.put(USERINFO.IMAGE_URL, photoUrl);
userInfo.put(USERINFO.EMAIL, email);
}
}
示例5: doInBackground
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... voids) {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user != null) {
for(UserInfo info : user.getProviderData()) {
switch(info.getProviderId()) {
case GoogleAuthProvider.PROVIDER_ID:
logoutGoogle();
break;
case FacebookAuthProvider.PROVIDER_ID:
logoutFacebook();
break;
case TwitterAuthProvider.PROVIDER_ID:
logoutTwitter();
break;
}
}
FirebaseAuth.getInstance().signOut();
}
return null;
}
示例6: showProviders
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
private void showProviders(FirebaseUser user) {
List<? extends UserInfo> providers = user.getProviderData();
for (int i = 0; i < providers.size(); i++) {
UserInfo userInfo = providers.get(i);
RadioButton radioButton = createRadio(userInfo.getProviderId());
radioButton.setId(i);
if(userInfo.getPhotoUrl()!= null && userInfo.getPhotoUrl().equals(user.getPhotoUrl())) {
radioButton.setChecked(true);
}
providersLayout.addView(radioButton);
}
providersLayout.setOnCheckedChangeListener((group, checkedId) -> {
Uri uri = providers.get(checkedId).getPhotoUrl();
showImageAvatar(uri);
});
}
示例7: getCredentialsFromFirebaseUser
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
/**
* Make a list of {@link Credential} from a FirebaseUser. Useful for deleting Credentials, not
* for saving since we don't have access to the password.
*/
private static List<Credential> getCredentialsFromFirebaseUser(@NonNull FirebaseUser user) {
if (TextUtils.isEmpty(user.getEmail()) && TextUtils.isEmpty(user.getPhoneNumber())) {
return Collections.emptyList();
}
List<Credential> credentials = new ArrayList<>();
for (UserInfo userInfo : user.getProviderData()) {
if (FirebaseAuthProvider.PROVIDER_ID.equals(userInfo.getProviderId())) {
continue;
}
String type = ProviderUtils.providerIdToAccountType(userInfo.getProviderId());
credentials.add(new Credential.Builder(
user.getEmail() == null ? user.getPhoneNumber() : user.getEmail())
.setAccountType(type)
.build());
}
return credentials;
}
示例8: DashboardAdapter
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
public DashboardAdapter(Context context) {
Calendar calendar = Calendar.getInstance();
int today = calendar.get(Calendar.DAY_OF_WEEK);
// Today is default
rowItems.add(new Section(context.getString(R.string.section_title_today), getSectionDate(calendar)));
calendar.add(Calendar.DAY_OF_YEAR, 1);
if (today >= Calendar.MONDAY && today <= Calendar.WEDNESDAY) {
rowItems.add(new Section(context.getString(R.string.section_title_tomorrow), getSectionDate(calendar)));
calendar.add(Calendar.DAY_OF_YEAR, 1);
rowItems.add(new Section(context.getString(R.string.section_title_this_week), getSectionDate(calendar)));
} else if (today == Calendar.THURSDAY) {
rowItems.add(new Section(context.getString(R.string.section_title_tomorrow), getSectionDate(calendar)));
calendar.add(Calendar.DAY_OF_YEAR, 1);
rowItems.add(new Section(context.getString(R.string.section_title_weekend), getSectionDate(calendar)));
} else if (today == Calendar.FRIDAY)
rowItems.add(new Section(context.getString(R.string.section_title_weekend), getSectionDate(calendar)));
else if (today == Calendar.SATURDAY)
rowItems.add(new Section(context.getString(R.string.section_title_tomorrow), getSectionDate(calendar)));
calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
if (calendar.getFirstDayOfWeek() != Calendar.SUNDAY || today != Calendar.SUNDAY)
calendar.add(Calendar.WEEK_OF_YEAR, 1);
rowItems.add(new Section(context.getString(R.string.section_title_next_week), getSectionDate(calendar)));
// TODO: Holiday and interval sections (between two holidays, to give a clearer overview over whats happening in the long run)
calendar.add(Calendar.WEEK_OF_YEAR, 1);
rowItems.add(new Section("Until the end of the universe", getSectionDate(calendar)));
// TODO: Listen on login
UserInfo userInfo = FirebaseAuth.getInstance().getCurrentUser();
if (userInfo != null) {
DocumentReference userReference = FirebaseFirestore.getInstance()
.collection("users")
.document(userInfo.getUid());
userReference.collection("groups")
.addSnapshotListener(this);
userReference.collection("items")
.addSnapshotListener(new GroupItemsChangeListener(FirebaseAuth.getInstance().getCurrentUser().getUid()));
}
}
示例9: init
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
public void init() {
// Initialize listener.
// ...
FacebookSdk.sdkInitialize(activity);
// FacebookSdk.setApplicationId(activity.getString(R.string.facebook_app_id));
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
for (UserInfo usr : user.getProviderData()) {
if (usr.getProviderId().equals("facebook.com")) {
Utils.d("FB:AuthStateChanged:signed_in:"+
user.getUid());
successLogin(user);
}
}
} else {
// User is signed out
Utils.d("FB:onAuthStateChanged:signed_out");
successLogOut();
}
// update user details;
}
};
// AppEventsLogger.activityApp(activity);
initCallbacks();
onStart();
Utils.d("Facebook auth initialized.");
}
示例10: init
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
public void init() {
TwitterAuthConfig authConfig = new TwitterAuthConfig(
activity.getString(R.string.twitter_consumer_key),
activity.getString(R.string.twitter_consumer_secret));
Fabric.with(activity, new Twitter(authConfig));
mAuth = FirebaseAuth.getInstance();
twitterAuthClient = new TwitterAuthClient();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
for (UserInfo usr : user.getProviderData()) {
if (usr.getProviderId().equals("twitter.com")) {
Utils.d("Twitter:AuthStateChanged:signed_in:"+
user.getUid());
successSignIn(user);
}
}
} else {
// User is signed out
Utils.d("Twitter:onAuthStateChanged:signed_out");
successSignOut();
}
// update firebase auth dets.
}
};
onStart();
}
示例11: setupUserFirstTime
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
public static User setupUserFirstTime(FirebaseUser firebaseUser, Context context) {
User user = new User(firebaseUser.getUid(),
firebaseUser.getEmail(),
firebaseUser.getDisplayName(),
firebaseUser.getPhotoUrl() == null ? null : firebaseUser.getPhotoUrl().toString(),
DateUtils.getCurrentTimeString());
try {
if (user.getPhotoUrl() == null) {
for (UserInfo userInfo : firebaseUser.getProviderData()) {
if (userInfo.getPhotoUrl() != null) {
user.setPhotoUrl(userInfo.getPhotoUrl().toString());
break;
}
}
}
} catch (Exception ex) {
}
Folder myBooksFolder = new Folder();
myBooksFolder.setId(UUID.randomUUID().toString());
myBooksFolder.setDescription(context.getResources().getString(R.string.tab_my_books));
myBooksFolder.setCustom(false);
user.setFolders(Collections.singletonMap(FirebaseDatabaseHelper.REF_MY_BOOKS_FOLDER, myBooksFolder));
return user;
}
示例12: firebaseUserToJSONObject
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
private static JSONObject firebaseUserToJSONObject(FirebaseUser firebaseUser) throws Exception {
JSONObject jsonUser = userInfoToJSONObject((UserInfo) firebaseUser);
jsonUser.put("isAnonymous", firebaseUser.isAnonymous());
JSONArray providerDataArray = new JSONArray();
for (UserInfo userInfo : firebaseUser.getProviderData()) {
providerDataArray.put(userInfoToJSONObject(userInfo));
}
jsonUser.put("providerData", providerDataArray);
return jsonUser;
}
示例13: userInfoToJSONObject
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
private static JSONObject userInfoToJSONObject(UserInfo userInfo) throws Exception {
Uri photoUrl = userInfo.getPhotoUrl();
JSONObject jsonUser = new JSONObject();
jsonUser.put("uid", userInfo.getUid());
jsonUser.put("displayName", userInfo.getDisplayName());
jsonUser.put("email", userInfo.getEmail());
jsonUser.put("photoURL", (photoUrl != null) ? photoUrl.toString() : null);
jsonUser.put("providerId", userInfo.getProviderId());
jsonUser.put("emailVerified", userInfo.isEmailVerified());
return jsonUser;
}
示例14: onAuthStateChanged
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null && firebaseBugFlag) {
firebaseBugFlag = false;
for (UserInfo profile : user.getProviderData()) {
String providerId = profile.getProviderId();
if (providerId.equals(FIREBASE_PROVIDER_ID)) {
if (!user.isAnonymous()) {
if (context != null) {
String name = profile.getDisplayName();
String email = profile.getEmail();
Uri photoUrl = profile.getPhotoUrl();
String photo = photoUrl != null ? photoUrl.toString() : "";
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = shared.edit();
editor.putString(SSConstants.SS_USER_NAME_INDEX, name);
editor.putString(SSConstants.SS_USER_EMAIL_INDEX, email);
editor.putString(SSConstants.SS_USER_PHOTO_INDEX, photo);
editor.commit();
}
}
SSEvent.track(SSConstants.SS_EVENT_APP_OPEN);
openApp();
}
}
}
}
示例15: invalidateEditAccountPref
import com.google.firebase.auth.UserInfo; //导入依赖的package包/类
/**
* Update the visibility of the edit account preference based on whether the current user
* is authenticated using the email provider.
*/
private void invalidateEditAccountPref() {
mPrefEditAccount.setVisible(false);
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user != null) {
for(UserInfo info : user.getProviderData()) {
if(info.getProviderId().equals(EmailAuthProvider.PROVIDER_ID)) {
mPrefEditAccount.setVisible(true);
return;
}
}
}
}