微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – firebase集成错误:Google Play服务已过期

我正在尝试将Firebase集成到我的Android应用程序中.我正在使用这个tutorial.我更新了我的sdk管理器,添加了google-services.json并完成了网站中提到的所有内容.我仍然收到此Google Play服务过时错误.我想获取设备令牌ID,以便我可以在Login Activity中将其发送到服务器.获取设备令牌ID还需要做些什么吗?

表现

<?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>

app的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

解决方法:

我认为这是设备方面的问题.看看你的logcat:

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

似乎您的设备未运行所需版本的Google Play服务.尝试更新设备上的Google Play服务,这应该可以解决此问题.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐