2014-11-19 10 views
0

내 Android 용 Google Play 서비스 확인을하려고합니다. 나는이 링크에서 YT 가이드 다음 : https://www.youtube.com/watch?v=i2lKeTJpaWc 을 그리고 다음 코드 생성 : 문제없이 제대로 실행Android 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; 
} 

}

답변

0

오류가 당신이 isGooglePlayServicesAvailableContext를 전달해야 알 수 있듯이. 이를 위해 당신은 아마 당신의 servicesOK 방법에 인수로 컨텍스트를 가져하기를 원할 것입니다 :

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

다음과 같은 활동에서이 메소드를 호출 완벽한 일

servicesOK(this); 
+0

가, 감사합니다! – Sletten