2016-07-15 2 views
4

Я пытаюсь интегрировать Firebase в приложение для Android. Я использую это tutorial. Я обновил свой менеджер sdk, добавил google-services.json и сделал все, как указано на веб-сайте. Тем не менее, я получаю эту ошибку Google Play services out of date. Я хочу получить идентификатор токена устройства, чтобы я мог отправить его на сервер в режиме входа. Есть ли что-то еще, что мне нужно сделать, чтобы получить идентификатор токена устройства?ошибка интеграции с firebase: службы Google Play устарели

Manifest

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="MY_PACKAGE"> 

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



    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:launchMode="singleTask" 
     android:theme="@style/MyTheme"> 
     <activity android:name=".SplashActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".MainActivity" /> 
     <activity android:name=".LoginActivity" android:theme="@style/AppTheme" android:label="@string/signin"/> 
     <activity android:name=".RegisterActivity" android:theme="@style/AppTheme" android:label="@string/cac"/> 
     <service android:name=".services.RegistrationIntentService" android:exported="false"/> 
     <service 
      android:name=".services.FCMMessageHandler" 
      android:exported="false" > 
      <intent-filter> 
       <action android:name="com.google.firebase.MESSAGING_EVENT" /> 
      </intent-filter> 
     </service> 
     <service 
      android:name=".services.MyInstanceIDListenerService" 
      android:exported="false"> 
      <intent-filter> 
       <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 
      </intent-filter> 
     </service> 
    </application> 

</manifest> 

build.gradle приложения в

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    defaultConfig { 
     applicationId "MY_PACKAGE" 
     minSdkVersion 11 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.2.1' 
    compile 'com.android.volley:volley:1.0.0' 
    compile 'com.google.firebase:firebase-messaging:9.2.1' 
    compile 'com.google.android.gms:play-services:9.2.1' 
    compile 'com.android.support:multidex:1.0.1' 
} 

apply plugin: 'com.google.gms.google-services' 

сервис

public class RegistrationIntentService extends IntentService { 

    // abbreviated tag name 
    private static final String TAG = "RegIntentService"; 
    public static final String SENT_TOKEN_TO_SERVER = "sentTokenToServer"; 
    public static final String FCM_TOKEN = "FCMToken"; 

    public RegistrationIntentService() { 
     super(TAG); 
    } 

    @Override 
    protected void onHandleIntent(Intent intent) { 
     // Make a call to Instance API 
     FirebaseInstanceId instanceID = FirebaseInstanceId.getInstance(); 
     String senderId = getResources().getString(R.string.gcm_defaultSenderId); 
     SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); 

     try { 
      // request token that will be used by the server to send push notifications 
      String token = instanceID.getToken(); 
      Log.d(TAG, "FCM Registration Token: " + token); 
      System.out.println("Token:" + token); 

      sharedPreferences.edit().putString(FCM_TOKEN, token).apply(); 
      // pass along this data 
      sendRegistrationToServer(token); 
     } catch (Exception e) { 
      e.printStackTrace(); 
      Log.d(TAG, "Failed to complete token refresh", e); 
      // If an exception happens while fetching the new token or updating our registration data 
      // on a third-party server, this ensures that we'll attempt the update at a later time. 
      sharedPreferences.edit().putBoolean(SENT_TOKEN_TO_SERVER, false).apply(); 
     } 
    } 

    private void sendRegistrationToServer(String token) { 
     // send network request 

     // if registration sent was successful, store a boolean that indicates whether the generated token has been sent to server 
     SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); 
     sharedPreferences.edit().putBoolean(SENT_TOKEN_TO_SERVER, true).apply(); 
    } 
} 

LogCat

07-15 15:02:59.004 24479-24707/com.sam.bidnextjob I/FA: Tag Manager is not found and thus will not be used 
07-15 15:02:59.028 24479-24707/com.sam.bidnextjob W/GooglePlayServicesUtil: Google Play services out of date. Requires 9256000 but found 9083234 
07-15 15:02:59.029 24479-24479/com.sam.bidnextjob W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null} 
07-15 15:03:59.033 24479-26561/com.sam.bidnextjob W/FA: Tasks have been queued for a long time 

ответ

2

Я думаю, что это проблема с устройством. Глядя на ваш ловушка:

Google Play services out of date. Requires 9256000 but found 9083234

Похоже, на вашем устройстве не установлена ​​требуемая версия услуг Google Play. Попробуйте обновить сервисы Google Play на устройстве и устранить эту проблему.

+0

Как я уже говорил в ~ Al Zill, я обновил сервисы Google Play, а также хранилище, прежде чем интегрировать firebase. На мобильном устройстве установлена ​​ОС Android 5.1. Я не думаю, что я могу обновить игровые сервисы. Нужно ли мне также устанавливать файлы библиотек API 24 (Android N)? @Arthur –

+0

Я говорил о версии сервисов Google Play на устройстве. Проверьте настройки> Службы> Службы Google Play и проверьте версию. –

+0

Спасибо Артуру за разъяснение. Я обновил игровые сервисы на мобильных устройствах и решил его решить. Но теперь токен должен быть сгенерирован. Но я получаю «токен регистрации FCM: null» в LogCat. @Артур –

0

Помимо Google Play службы, также необходимо обновить Google хранилище до новейших. Я не знаю, почему нет документации об этом, но обновление репозитория Google решает мою проблему.

+0

Да, я обновил оба. –

Смежные вопросы