Я пытаюсь выполнить проверку сервисов Google для моего приложения для Android. Я последовал за руководство УТ по этой ссылке: https://www.youtube.com/watch?v=i2lKeTJpaWc И создал следующий код:Ошибка контекста Google Google для GooglePlayServices
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;
}
}
Это работало идеально, спасибо! – Sletten