繁体   English   中英

Firebase推送通知即将在移动设备上发布,但不会在平板电脑上发布

[英]Firebase push notification is coming on mobile but not on tablet

对于Firebase的推送通知,我有一个非常基本的设置,并且可以在我的手机上正常工作 在3到6秒钟内,我会收到通知。 当我尝试在平板电脑上运行同一应用程序时,我根本没有收到任何通知 有人可以建议点什么。
我使用的平板电脑是:
联想TAB 2 A7-20F,在Android 4.4.2上运行

这是我的代码。

项目build.gradle

buildscript {
    ...
    dependencies {
        ...
        classpath 'com.google.gms:google-services:3.0.0'
    }
}


应用程式build.gradle

apply plugin: 'com.android.application'
...
dependencies {
    ...
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    ...
}
apply plugin: 'com.google.gms.google-services'


清单文件

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


MyFirebaseInstanceIdService

public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {
    private static final String TAG = MyFirebaseInstanceIdService.class.getName();

    @Override
    public void onTokenRefresh() {
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);
    }
}


MyFirebaseMessagingService

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = MyFirebaseMessagingService.class.getName();
    private static final String PAYLOAD = "payload";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        triggerNotification();
    }

    private void triggerNotification() {
        final NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
        final Notification notification = new NotificationCompat
                .Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Content title")
                .setContentText("Content text")
                .build();
        notificationManager.notify(1, notification);
    }
}

更新我在5到6个小时后检查了平板电脑,并看到了所有通知。 也许是因为有一些时间设置。 我仍然没有收到通知,因为我没有安排任何通知。 我在每个通知中都选择了“立即发送”选项。 我真的很感谢任何建议。

更新我尝试与其他网络连接,以防万一,事实证明是由于防火墙的缘故。 办公网络已安装防火墙,而我的家庭网络没有防火墙。 即使在移动数据上也可以正常工作。

从更新gms和Firebase开始。 这里的文档应该有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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