我有一个非常基本的设置推送通知从防火墙和它的很好地工作在我的移动。在3到6秒内,我收到通知。同样的应用程序,当我试图在平板电脑上运行时,我根本没有收到任何通知。有人能给我点建议吗。
我使用的平板是:
联想TAB 2 A7-20F,运行在Android 4.4.2上
这是我的密码。
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'报表文件
<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小时后检查了我的平板电脑,我看到了我所有的通知。也许是因为时间的安排。我仍然没有得到它,因为我没有安排任何通知。我在每次通知中都选择了“立即发送”选项。如果有任何建议我会很感激的。
UPDATE,我试着连接不同的网络,以防万一,事实证明,这是因为防火墙。办公室网络安装了防火墙,我的家庭网络没有防火墙。即使在移动数据上,它也运行得很好。
发布于 2017-10-06 12:48:52
从更新gms和Firebase开始。docs 这里应该会有所帮助。
https://stackoverflow.com/questions/46605986
复制相似问题