简体   繁体   中英

I can't get Firebase token from Huawei p40 series device

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
        }
});

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.

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

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

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'm better 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.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM