FCM отправляет уведомления в мою старую версию приложения, но не в обновленной версии - PullRequest
0 голосов
/ 18 октября 2018

Я впервые использовал FCM.В моей первой реализации я использовал следующий подход .Я получал уведомления отлично.Теперь я обновил свое приложение и попробую использовать следующий обновленный подход .Но проблема, с которой я сталкиваюсь, заключается в том, что я получаю уведомления о моей предыдущей версии еще при отправке их из консоли уведомлений.

Я обновил свой Gradle как

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
        transitive = true;
    }
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support:design:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:cardview-v7:26.+'
    compile 'com.android.support:support-v4:26.+'
    compile 'com.google.firebase:firebase-core:16.0.4'
    compile 'com.google.android.gms:play-services-ads:15.0.1'
    compile 'com.google.firebase:firebase-messaging:17.3.3'
    testCompile 'junit:junit:4.12' } apply plugin: 'com.google.gms.google-services'
}

ВторойПроблема заключается в том, что когда я использую этот метод для получения нового токена в моем методе onCreate MainActivity.java, getToken () и getActivity () становится красным.

 FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(this, instanceIdResult -> {
                    String newToken = instanceIdResult.getToken();
                    Log.e("newToken", newToken);
                    getActivity().getPreferences(Context.MODE_PRIVATE).edit().putString("fb", newToken).apply();
                });

                Log.d("newToken", getActivity().getPreferences(Context.MODE_PRIVATE).getString("fb", "empty :("));

Я не могу решить эту проблему.Пожалуйста, помогите!

Вот мой сервис:

public class MyFirebaseMessagingService extends FirebaseMessagingService {



    private static final String TAG = "FCM Service";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // TODO: Handle FCM messages here.
        // If the application is in the foreground handle both data and notification messages here.
        // Also if you intend on generating your own notifications as a result of a received FCM
        // message, here is where that should be initiated.
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
    }

    public void onNewToken(String token) {
        Log.d(TAG, "Refreshed token: " + token);

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.
        sendRegistrationToServer(token);
    }
    private void sendRegistrationToServer(String token) {
        // TODO: Implement this method to send token to your app server.
    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...