2017-10-06 59 views
0

我有一個非常基本的設置,用於從Firebase推送通知,其在我的移動上正常工作。在3到6秒內,我收到通知。當我嘗試在平板電腦上運行時,我的相同應用程序根本沒有收到任何通知。有人可以提出建議嗎?
我使用的平板電腦是:
Lenovo TAB 2 A7-20F,在Android上運行4.4.2


這是我的代碼。

項目的build.gradleFirebase推送通知在移動設備上發佈,但不在平板電腦上

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

UPDATE 我檢查了我的平板電腦後5-6小時,我看到了我的所有通知。也許這是因爲一段時間的設定。我還沒有得到它,因爲我沒有安排任何通知。每次通知我都選擇了「立即發送」選項。我真的很感激任何建議。

UPDATE 我試圖連接不同的網絡,以防萬一,因爲事實證明,這是因爲防火牆發生。辦公室網絡安裝了防火牆,我的家庭網絡沒有防火牆。即使在移動數據上也能正常工作。

回答

0

從更新gms和Firebase開始。文檔here應該有所幫助。

相關問題