[英]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.