简体   繁体   中英

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 . Within 3 to 6 secs I get the notification. 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

Here is my code.

Project build.gradle

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


App 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

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

UPDATE I checked my tablet after 5-6 hrs and I saw all my notifications. 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. The docs here should help.

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