11

I usually get the token with this method, but with the arrival of the huawei p40 series I can't get the token with those

FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( this,  new OnSuccessListener<InstanceIdResult>() {
        @Override
        public void onSuccess(InstanceIdResult instanceIdResult) {
            final String token = instanceIdResult.getToken(); // i can't get this
        }
});
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Axel López
  • 266
  • 1
  • 5
  • 13

4 Answers4

17

P40 contains Huawei Mobile Services. These devices don't have Google Mobile Services so Firebase won't work. There is alternative called Push Kit - https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/push-introduction

If you want to make it all working on a one platform, you can try:

They are working with Google and Huawei.

deadfish
  • 11,996
  • 12
  • 87
  • 136
5

As new Huawei phones are banned from using GMS, firebase cannot be used on new Huawei phones. Huawei already provided such notification service, called HMS Push Kit, in order to make push notification available on the devices which don’t have GMS, like mate30, mate30 pro, P40 and any other Huawei new devices. If you want your app to run on these phones, integrate Huawei Push Kit.

Please kindly refer to the links:

Development Guide

Sample Code on Github

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
3

For Flutter projects:

I don't like to use third party like OneSignal to push notifications for many reasons, one of it for example OneSignal not provide way to handle background data in its Flutter plugin like FirebaseMessaging.onBackgroundMessage(...) in firebase_messaging, or Push.registerBackgroundMessageHandler(...) in huawei_push...

So I prefer to use two plugin (in same project):

1- https://pub.dev/packages/firebase_messaging for Android without HMS and IOS...

2- https://pub.dev/packages/huawei_push it work on Android with HMS.

enter image description here

AnasSafi
  • 5,353
  • 1
  • 35
  • 38
1

FCM is Firebase cloud Messaging service. New generation of Huawei devices (Huawei P40 series , Mate 30 series,) don't support Google services like Google Map ,FCM, etc. If you want to use your app successfully , your app providers must be integrated HMS service or 3rd party solutions after that You can use related app without any problem.

I think that you can replace it with HMS Push kit or you can use 3rd party push providers. for more information please visit link

Serkan
  • 90
  • 6