如何将firebasemessagingservice更新到最新版本?

时间:2019-07-14 13:27:32

标签: android firebase firebase-cloud-messaging

我收到一条错误消息,提示“错误:类,接口或枚举预期”,我从firebasemessagingservice中发现它需要更新,我不知道该怎么做。请帮忙。

import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onNewToken(String s) {
        super.onNewToken(s);
        Log.e("NEW_TOKEN",s);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
    }
}

    private void sendRegistrationToServer(String token) {
        //You can implement this method to store the token on your server
        //Not required for current project
    }

}

2 个答案:

答案 0 :(得分:0)

您在代码中添加了一个额外的“”。删除并重新编译

正确的代码:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onNewToken(String s) {
        super.onNewToken(s);
        Log.e("NEW_TOKEN",s);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
    }


    private void sendRegistrationToServer(String token) {
        //You can implement this method to store the token on your server
        //Not required for current project
    }

}

答案 1 :(得分:0)

这是androidManifest文件

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

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
    android:name=""
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <!-- Disable opening of launcher Activity -->
    <meta-data
        android:name="com.onesignal.NotificationOpened.DEFAULT"
        android:value="DISABLE" />

    <activity
        android:name=""
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=""
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=""
        android:configChanges="orientation|keyboardHidden|screenSize" />
    <activity
        android:name="com.tools.vactivities.ActivityRecipesDetail"
        android:configChanges="orientation|keyboardHidden|screenSize" />

    <!--admob-->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

    <!--fcm-->
    <service android:name="com.tools.notification.MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service
        android:name=".MyFirebaseMessagingService"
        android:stopWithTask="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service
        android:name="com.tools.notification.NotificationExtenderExample"
        android:exported="false"
        android:permission="android.permission.BIND_JOB_SERVICE">
        <intent-filter>
            <action android:name="com.onesignal.NotificationExtender" />
        </intent-filter>
    </service>

</application>