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 我试图连接不同的网络,以防万一,因为事实证明,这是因为防火墙发生。办公室网络安装了防火墙,我的家庭网络没有防火墙。即使在移动数据上也能正常工作。