LoginSignup
0
0

More than 3 years have passed since last update.

Android端末におけるHUAWEI IDログイン機能の詳細実装手順1-ソリューションの概要

Last updated at Posted at 2021-04-01

HUAWEI IDログイン機能

HUAWEI IDログインはファーウェイが提供しているソーシャルログイン機能です。主にHMS端末で使われているため、GMS端末では利用できないと勘違いしやすいですが、ちゃんと利用できます。

HMSとGMS両方に対応したHUAWEI IDログイン実装のソリューションの概要

ソリューションの基本概念は単純です。

HMS Account Kit.png

1. 端末にHMSが入っていれば、HMS Account KitのAndroid SDKを使います。
2. 端末にHMSが入っていなければ、HMS Account KitのREST APIを使います。

Design Pattern.png

3. Strategy パターンを利用し、ログイン(signIn)や権限取り消し(cancelAuthorization)など共通している動作を抽出してインターフェースにまとめ、ビジネスロジックはインターフェースを継承したクラスに入れます。

HuaweiIdLogic.kt
interface HuaweiIdLogic {
    fun signIn(activity: Activity)
    fun signOut()
    fun cancelAuthorization(context: Context)
    fun update(context: Context, intent: Intent)
    fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
}
HmsHuaweiIdLogic.kt
class HmsHuaweiIdLogic() : HuaweiIdLogic {
    override fun signIn(activity: Activity) {}
    override fun signOut() {}
    override fun cancelAuthorization(context: Context) {}
    override fun update(context: Context, intent: Intent) {}
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {}
}
NonHmsHuaweiIdLogic.kt
class NonHmsHuaweiIdLogic() : HuaweiIdLogic {
    override fun signIn(activity: Activity) {}
    override fun signOut() {}
    override fun cancelAuthorization(context: Context) {}
    override fun update(context: Context, intent: Intent) {}
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {}
}

シリーズ

GitHub

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0