2017-03-22 7 views
0

Firebaseを使用しているため、アプリの起動時にサポートされているバージョンのGoogle Playサービスがあることを確認する必要があります。 GooglePlayServicesUtilは推奨されていません。したがって、私は新しい光沢のあるGoogleApiAvailability APIを使用しており、アップグレードが必要かどうかを検出できます。Android 6以降でGoogle Playサービスエラーを解決するにはどうすればよいですか?

しかし私が使用するときは、GoogleApiAvailability.getErrorDialogは必要なインテントを起動しません。それは何もしません。インターネットのトロールは有用なコードサンプルを明らかにしません。理想的には、独自のカスタムダイアログを作成してpendingIntentを起動したいと思いますが、これも難解です。私のコード:

final GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance(); 
    final int resultCode = googleAPI.isGooglePlayServicesAvailable(this); 
    if (resultCode == ConnectionResult.SUCCESS) { 
     if (isOnline()) { 
      app.init(this, this); 
     } 
    } else { 
      switch (resultCode) { 
       case SERVICE_VERSION_UPDATE_REQUIRED: 
        Dialog updateDialog = googleAPI.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST, mOnCancelFinishApp); 
        updateDialog.setOnDismissListener(mOnDismissFinishApp); 
        updateDialog.setCanceledOnTouchOutside(false); 
        updateDialog.show(); 
        ... 

アップデート:私のGradleは

..... 
dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 

    compile('com.microsoft.aad:adal:2.0.1-alpha') { 
     exclude group: 'com.android.support' 
    } 
    compile 'com.google.android.gms:play-services-location:10.0.0' 
    compile('com.crashlytics.sdk.android:answers:[email protected]') { 
     transitive = true; 
    } 
    compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
     transitive = true; 
    } 
    compile 'com.android.support:appcompat-v7:25.0.0' 
    compile 'com.android.support:design:25.0.0' 
    compile 'com.android.support:support-v4:25.0.0' 
    compile 'com.google.android.gms:play-services-maps:10.0.0' 
    compile 'com.google.android.gms:play-services-location:10.0.0' 
    compile 'com.android.support:cardview-v7:25.0.0' 
    compile 'com.google.android.gms:play-services-analytics:10.0.0' 
    compile 'com.google.firebase:firebase-core:10.0.0' 
    provided 'org.glassfish:javax.annotation:10.0-b28' 
} 
apply plugin: 'com.google.gms.google-services' 

buildscript { 
    repositories { 
     maven { url 'https://maven.fabric.io/public' } 
    } 

    dependencies { 
     // These docs use an open ended version so that our plugin 
     // can be updated quickly in response to Android tooling updates 

     // We recommend changing it to the latest version from our changelog: 
     // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin 
     classpath 'io.fabric.tools:gradle:1.+' 
    } 
} 

apply plugin: 'io.fabric' 

repositories { 
    maven { url 'https://maven.fabric.io/public' } 
+0

ください。あなたのgradleファイルを更新する –

+0

@YogeshBorhade私は自分のgradleファイルからの依存関係を含んでいます。 – giulio

+0

あなたのグラデルファイルを投稿してください –

答えて

0

ご確認くださいGooglePlayServices利用可能かどうかこれらの依存関係を持ってい

Dialog errorDialog; 

private boolean checkPlayServices() { 

     GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); 

     int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(this); 

     if (resultCode != ConnectionResult.SUCCESS) { 
      if (googleApiAvailability.isUserResolvableError(resultCode)) { 

       if (errorDialog == null) { 
        errorDialog = googleApiAvailability.getErrorDialog(this, resultCode, 2404); 
        errorDialog.setCancelable(false); 
       } 

       if (!errorDialog.isShowing()) 
        errorDialog.show(); 

      } 
     } 

     return resultCode == ConnectionResult.SUCCESS; 
    } 
+0

これは私が見たMarshmallowの他の回答からコピーされているようです。 – giulio

0

これらの変更を試してください:

.... 
apply plugin: 'io.fabric' 

repositories { 
maven { url 'https://maven.fabric.io/public' } 


buildscript { 
repositories { 
    maven { url 'https://maven.fabric.io/public' } 
} 

dependencies { 
    // These docs use an open ended version so that our plugin 
    // can be updated quickly in response to Android tooling updates 

    // We recommend changing it to the latest version from our changelog: 
    // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin 
    classpath 'io.fabric.tools:gradle:1.+' 
} 
} 

dependencies { 
compile fileTree(include: ['*.jar'], dir: 'libs') 

compile('com.microsoft.aad:adal:2.0.1-alpha') { 
    exclude group: 'com.android.support' 
} 
compile 'com.google.android.gms:play-services-location:10.0.0' 
compile('com.crashlytics.sdk.android:answers:[email protected]') { 
    transitive = true; 
} 
compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
    transitive = true; 
} 
compile 'com.android.support:appcompat-v7:25.0.0' 
compile 'com.android.support:design:25.0.0' 
compile 'com.android.support:support-v4:25.0.0' 
compile 'com.google.android.gms:play-services-maps:10.0.0' 
compile 'com.android.support:cardview-v7:25.0.0' 
compile 'com.google.android.gms:play-services-analytics:10.0.0' 
compile 'com.google.firebase:firebase-core:10.0.0' 
provided 'org.glassfish:javax.annotation:10.0-b28' 
} 

apply plugin: 'com.google.gms.google-services' 
関連する問題