GenAuth DocsDocuments
Concepts
User Guide
Development Integration
Metadata
Development Integration
Multi-tenant (beta)
Console Documentation
Multi-tenant Console
Tenant Console
Saas Application Demo
Concepts
User Guide
Development Integration
Metadata
Development Integration
Multi-tenant (beta)
Console Documentation
Multi-tenant Console
Tenant Console
Saas Application Demo
Old version
  • Single Page Web Application

  • Mobile and Client Applications

    • Android

      • Quick Start
      • Hosted Pages
      • Components

      • APIs

      • Social Login

      • Typical Scenarios

        • 退出登录
        • 闪屏界面
        • 凭证管理
        • 个人中心
        • WebView
      • Private Deployment
      • Version History
    • C#

    • Flutter

    • iOS

    • React Native
  • Standard Web Application

  • Framework Integration

  • Others

  1. Development Integration
  2. /
  3. Mobile and Client Applications
  4. /
  5. Android
  6. /
  7. Typical Scenarios
  8. /
  9. 个人中心

¶ 个人中心

Update time: 2025-04-11 11:21:15
Edit

Guard 提供默认的个人中心界面,包括个人信息修改。分两种常见场景使用:

¶ Activity

继承 Guard 里面的 UserProfileActivity

public class MeActivity extends UserProfileActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Button btn = findViewById(R.id.btn_logout);
        btn.setOnClickListener(v -> logout());
    }

    private void logout() {
        AuthClient.logout((code, message, data)->{
            // go to your home page which should in turn show login page
        });
    }
}

¶ Fragment

在需要使用个人中心的布局文件里面增加:

<fragment
    android:id="@+id/fragment_user_profile"
    android:name="cn.authing.guard.activity.UserProfileFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

然后在 activity 里面,增加以下代码:

private UserProfileFragment fragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // replace with your activity layout
    setContentView(R.layout.authing_activity_user_profile); 
    fragment = (UserProfileFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_user_profile);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK && requestCode == 1000) {
        fragment.uploadAvatar(data.getData());
    }
}

更新头像需要在 Activity 里面重载 onActivityResult 函数,更新其它个人信息的逻辑已经在 UserProfileFragment 里面处理。

Previous article: 凭证管理 Next article: WebView
  • Activity
  • Fragment

User identity management

Integrated third-party login
Customized authentication process

Enterprise internal management

Single sign-on
Multi-factor authentication
Permission management

Developer

Development Documentation
GitHub (opens new window)

Company

official@genauth.ai
16th Floor, Building B, Beichen Century Center, Chaoyang District, Beijing (Total)
Room 406, 4th Floor, Block B, No. 200, Tianfu Fifth Street, High-tech Zone, Chengdu (Branch)

© Beijing Steamory Technology Co., Ltd.