Java Android GooglePlayServices上下文错误

Java Android GooglePlayServices上下文错误,java,android,class,android-context,Java,Android,Class,Android Context,我正在尝试对我的android应用程序进行Google play服务检查。 我在这个链接上遵循了yt指南: 并创建了以下代码: public boolean servicesOK() { int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (isAvailable == ConnectionResult.SUCCESS) { return true;

我正在尝试对我的android应用程序进行Google play服务检查。 我在这个链接上遵循了yt指南: 并创建了以下代码:

public boolean servicesOK() {
    int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

    if (isAvailable == ConnectionResult.SUCCESS) {
        return true;
    }
    else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
        dialog.show();
    }
    else {
        Toast.makeText(this, "Can't connect to Google Play services", Toast.LENGTH_SHORT).show();
    }
    return false;
}
代码执行正确,没有任何问题,因此我决定将其放入类文件中。那就是问题发生的时候;我收到以下错误消息:

"The method isGooglePlayServicesAvailable(Context) in the type GooglePlayServicesUtil is not applicable for the arguments (PlayServices)"
该类的完整代码:

package com.test.testmaps2;
import android.app.Dialog;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;

public class PlayServices {
private static final int GPS_ERRORDIALOG_REQUEST = 9001;


public boolean servicesOK() {
    int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

    if (isAvailable == ConnectionResult.SUCCESS) {
        return true;
    }
    else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
        dialog.show();
    }
    else {
        Toast.makeText(this, "Can't connect to Google Play services", Toast.LENGTH_SHORT).show();
    }
    return false;
}

}

错误提示您需要将上下文传递给iGoogle PlayServicesAvailable。为此,您可能希望获取上下文作为servicesOK方法的参数:

public boolean servicesOK(Context ctx) {
    int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(ctx);
然后从活动中调用此方法,如:

servicesOK(this);