LoginSignup
0
0

More than 3 years have passed since last update.

Android端末におけるHUAWEI IDログイン機能の詳細実装手順3-HMS判定

Last updated at Posted at 2021-04-01

HMS判定方法

HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable()で判定します。
端末にHMSが入っている、戻り値がtrueになり、HMSが入っていなければ、戻り値がfalseになります。

if (com.huawei.hms.api.ConnectionResult.SUCCESS == HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context)) {
    // HMSあり
    // HMS Account KitのAndroid SDKを使います
} else {
    // HMSなし
    // HMS Account KitのREST APIを使います
}

Strategy パターンを使う場合、ソースコードが次のようになります。

MainActivity.kt
private lateinit var huaweiIdLogic: HuaweiIdLogic

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    ...

    huaweiIdLogic = if (com.huawei.hms.api.ConnectionResult.SUCCESS == HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context)) {
        HmsHuaweiIdLogic()
    } else {
        NonHmsHuaweiIdLogic()
    }
}

シリーズ

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