sGooglePlayServicesAvailable和get

sGooglePlayServicesAvailable和get

本文介绍了非静态方法isGooglePlayServicesAvailable和getErrorDialog不能从静态上下文中引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写此代码,它显示了无法从静态上下文引用错误非静态方法GoogleApiAvailability.isGooglePlayServicesAvailable(Context context)和GoogleApiAvailability.getErrorDialog(活动活动,int errorCode,int requestCode)的情况.

I am writing this code and it shows the error non-static method GoogleApiAvailability.isGooglePlayServicesAvailable(Context context) and GoogleApiAvailability.getErrorDialog (Activity activity, int errorCode, int requestCode) cannot be referenced from a static context.

package com.xamarin.gcmexample;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.GoogleApiAvailability;
import android.util.Log;
import android.widget.TextView;

public class Main extends AppCompatActivity {
    TextView msgText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        msgText = (TextView) findViewById(R.id.msgText);

    }
    protected void IsPlayServicesAvailable ()
    {
        int resultCode = GoogleApiAvailability.isGooglePlayServicesAvailable(this);
        if (resultCode == ConnectionResult.SUCCESS){
            msgText.setText("isGooglePlayServicesAvailable SUCCESS");

        }else{
            GoogleApiAvailability.getErrorDialog(this, resultCode, 1).show();
        }
    }

}

推荐答案

Nurlan已经指出了正确的答案.

Nurlan has already pointed the right answer.

替换您的方法

protected void IsPlayServicesAvailable() {
    int resultCode = GoogleApiAvailability.isGooglePlayServicesAvailable(this);

    if (resultCode == ConnectionResult.SUCCESS){
        msgText.setText("isGooglePlayServicesAvailable SUCCESS");
    } else {
        GoogleApiAvailability.getErrorDialog(this, resultCode, 1).show();
    }
}

作者

protected void IsPlayServicesAvailable() {
    int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);

    if (resultCode == ConnectionResult.SUCCESS){
        msgText.setText("isGooglePlayServicesAvailable SUCCESS");
    } else {
        GoogleApiAvailability.getInstance().getErrorDialog(this, resultCode, 1).show();
    }
}

这篇关于非静态方法isGooglePlayServicesAvailable和getErrorDialog不能从静态上下文中引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 21:32