简体   繁体   English

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

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

I have a very basic setup for push notification from firebase and its working fine on my mobile . 对于Firebase的推送通知,我有一个非常基本的设置,并且可以在我的手机上正常工作 Within 3 to 6 secs I get the notification. 在3到6秒钟内,我会收到通知。 The same application when I am trying to run on a tablet, I am not getting any notification at all. 当我尝试在平板电脑上运行同一应用程序时,我根本没有收到任何通知 Can someone please suggest something. 有人可以建议点什么。
Tablet I am using is: 我使用的平板电脑是:
Lenovo TAB 2 A7-20F, running on Android 4.4.2 联想TAB 2 A7-20F,在Android 4.4.2上运行

Here is my code. 这是我的代码。

Project build.gradle 项目build.gradle

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


App build.gradle 应用程式build.gradle

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


Manifest file 清单文件

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

UPDATE I checked my tablet after 5-6 hrs and I saw all my notifications. 更新我在5到6个小时后检查了平板电脑,并看到了所有通知。 Maybe it's because of some time setting. 也许是因为有一些时间设置。 I still did not get it as I did not schedule any notification. 我仍然没有收到通知,因为我没有安排任何通知。 I opted for "Send Now" option with every notification. 我在每个通知中都选择了“立即发送”选项。 I would really appreciate any suggestion. 我真的很感谢任何建议。

UPDATE I tried connecting with different network just in case and as It turned out it was happening because of the firewall. 更新我尝试与其他网络连接,以防万一,事实证明是由于防火墙的缘故。 Office network had firewall installed and my home network had no firewall. 办公网络已安装防火墙,而我的家庭网络没有防火墙。 It was working fine even on mobile data. 即使在移动数据上也可以正常工作。

Start with updating gms and Firebase. 从更新gms和Firebase开始。 The docs here should help. 这里的文档应该有所帮助。

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

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