首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google Api可用性问题

Google Api可用性问题
EN

Stack Overflow用户
提问于 2018-10-09 19:39:52
回答 2查看 1.5K关注 0票数 0

我试图在我的android项目中使用Google。当我调用以下函数时

代码语言:javascript
运行
复制
public boolean checkGoogleServices(){
        Log.d(TAG, "isServicesOk: checking google services version");
        int available = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(Home.this);

        if (available == ConnectionResult.SUCCESS){


            Log.d(TAG, "isServicesOk: Google Play Services is working");
            Toast.makeText(this, "OK", Toast.LENGTH_LONG).show();
            return true;

        }
        else if(GoogleApiAvailability.getInstance().isUserResolvableError(available)){

            Log.d(TAG, "isServicesOk: an error occured but we can fix it");
            Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog(Home.this, available, ERROR_DIALOG_REQUEST);
            dialog.show();


        }else{
            Toast.makeText(this, "You can't make maps request", Toast.LENGTH_LONG).show();


        }
        return false;

    }

if (available == ConnectionResult.SUCCESS)的结果是true,实际上,程序会在控制台上写日志"google服务正在工作“,但在那之后,它就会退出if并返回false

Google服务已正确安装在我的SDK中。

EN

Stack Overflow用户

发布于 2018-10-09 20:02:04

尝试这个以获得布尔值并打印

代码语言:javascript
运行
复制
    public static boolean checkPlayServices(Activity activity) {
        final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
        GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
        int resultCode = apiAvailability.isGooglePlayServicesAvailable(activity);
        if (resultCode != ConnectionResult.SUCCESS) {
            if (apiAvailability.isUserResolvableError(resultCode)) {
                apiAvailability.getErrorDialog(activity, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                        .show();
 Log.d(TAG, "This device have google play services");
            } else {
                Log.d(TAG, "This device does not have google play services");
            }
            return false;
        }
        return true;
    }

现在打印checkPlayServices(活动)

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52728218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档