Android接入Google Play Service

必须条件

如测试Google登录的条件:

  • 手机具备翻墙能力
  • 手机为Google手机或者安装Google Play service(各大应用市场搜索谷歌安装器)
  • 应用签名配置正确
  • google-services.json为最新并放置在module目录下

引入Google Play Service

参考:https://developers.google.com/android/guides/setup

配置AndroidManifest

1
2
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
1
2
3
4
<resources>
<!-- Android-Sdk\extras\google\m2repository\com\google\android\gms\play-services -->
<integer name="google_play_services_version">12451000</integer>
</resources>

判断Google Play Service是否可用

1
2
3
4
5
6
7
8
9
10
11
12
public static boolean isGooglePlayServicesAvailable(Activity activity) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
Integer resultCode = googleApiAvailability.isGooglePlayServicesAvailable(activity);
if (resultCode != ConnectionResult.SUCCESS) {
Dialog dialog = googleApiAvailability.getErrorDialog(activity, resultCode, 0);
if (dialog != null) {
dialog.show();
}
return false;
}
return true;
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :