2016-05-09 1 views
0

現在GooglePlayServicesにアクセスしようとしています。 AVD(API 23)上の他のすべての機能のインターネットはうまく動作しますが、私の実際のアプリに何が問題なのかよく分かりません。AVDでGooglePlayServicesに接続できません

接続しようとするたびに、Connectionに接続できませんでした。私はConnectionAPIを正しく設定したと思いますが、ConnectionRequestでは設定をカスタマイズしていません(単純化のため)。

これはいくつかの情報を提供する私のアプリのコードの一部です。

たManifest.xml

<?xml version="1.0" encoding="utf-8"?> 

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.INTERNET"/> 

<application 
    android:name=".Protoype2" 
    android:allowBackup="true" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".SettingsMenu" 
     android:label="@string/title_activity_settings_menu" 
     android:parentActivityName=".MainActivity" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <meta-data 
      android:name="android.support.PARENT_ACTIVITY" 
      android:value="com.example.denny.protoype2.MainActivity" /> 
    </activity> 
    <activity 
     android:name=".ViewingWindow" 
     android:label="@string/title_activity_viewing_window" 
     android:parentActivityName=".MainActivity" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <meta-data 
      android:name="android.support.PARENT_ACTIVITY" 
      android:value="com.example.denny.protoype2.MainActivity" /> 
    </activity> 
</application> 

のonCreate()。最後に、関連するクラス

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_viewing_window); 
    mRequestingLocationUpdates = ((Protoype2)getApplication()).getRequestingLocationUpdates(); 
    if (!mRequestingLocationUpdates) { 
     StoppedMessage(); 
    } 
    ExceedInstance = 0; 
    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .enableAutoManage(this, this) 
      .addApi(Drive.API) 
      .addScope(Drive.SCOPE_FILE) 
      .build(); 
    String[] LocationPermission = new String[]{Manifest.permission.ACCESS_FINE_LOCATION}; 
    if (ContextCompat.checkSelfPermission(ViewingWindow.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
     if (ActivityCompat.shouldShowRequestPermissionRationale(ViewingWindow.this, 
       Manifest.permission.ACCESS_FINE_LOCATION)) { 
      GPSExplanation(); 
     } else { 
      ActivityCompat.requestPermissions(ViewingWindow.this, 
        new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 
        MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); 
     } 

    } 
    onRequestPermissionsResult(MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION, LocationPermission, grantResults); 

    final Button BackButton = (Button)findViewById(R.id.VWBackButton); 
    BackButton.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent GoBackIntent = new Intent (ViewingWindow.this, MainActivity.class); 
      startActivity(GoBackIntent); 
     } 
    }); 
    updateValuesFromBundle(savedInstanceState); 

} 

から、接続のいくつかの定義済みの方法:あなたのAVDがGoogle PlayのサービスAPKの適切なバージョンを持っている場合

protected void onStart() { 
    super.onStart(); 
    mGoogleApiClient.connect(); 
} 

public void onConnected(Bundle connectionHint) { 
    createLocationRequest(); 
    if (mRequestingLocationUpdates) { 
     startLocationUpdates(); 
    } 
} 

protected LocationRequest createLocationRequest() { 
    return new LocationRequest(); 
} 

答えて

0

チェックは、onConnectionFailed()コールバックメソッドを実装します。エラーを解決し、発生したエラーの種類を判断するために使用できるパラメータConnectionResultを使用します。

エラーを解決するには、解像度がstartResolutionForResult(Activity, int)に渡された非負requestCodeでの活動から開始する必要があります。アプリケーションでアクティビティにonActivityResultを実装して、ユーザーが問題を解決した場合はconnect()を再度呼び出す必要があります(resultCodeはRESULT_OK)。あなたのアプリがonConnectionFailed()への呼び出しを受けて、このdocumentation、から基づい

)コールバック、あなたが提供ConnectionResultオブジェクトにhasResolution()を呼び出す必要があります。 trueを返す場合、アプリケーションはConnectionResultオブジェクトでstartResolutionForResult()を呼び出すことによって、ユーザーがエラーを解決するためにすぐに対応するように要求できます。

これを確認してください。questionそれが役に立てば幸い!

関連する問題