Android接入Google Play Service

必须条件

如测试Google登录的条件:

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

引入Google Play Service

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

配置AndroidManifest

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

判断Google Play Service是否可用

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;
}
上一篇 Glide错误IllegalArgumentException You cannot start a load for a destroyed activity
下一篇 Android使用Facebook的开放图谱发布图文分享
目录
文章列表
1 Java连接OpenOffice4的使用
Java连接OpenOffice4的使用
2
Jenkins构建任务
Jenkins构建任务
3
Android Studio 3.0下命令行打包自定义输出路径和输出命名
Android Studio 3.0下命令行打包自定义输出路径和输出命名
4
MySQL修改编码
MySQL修改编码
5
React.js集成Antd组件库
React.js集成Antd组件库
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。