Android Firebase推送通知将在手机上发布,但不会在平板电脑上发布
我对firebase的推送通知有一个非常基本的设置,它在我的手机上运行良好。在3到6秒内我收到了通知。当我尝试在平板电脑上运行相同的应用程序时,我根本没有收到任何通知。谁能给我提个建议吗。Android Firebase推送通知将在手机上发布,但不会在平板电脑上发布,android,firebase-cloud-messaging,tablet,Android,Firebase Cloud Messaging,Tablet,我对firebase的推送通知有一个非常基本的设置,它在我的手机上运行良好。在3到6秒内我收到了通知。当我尝试在平板电脑上运行相同的应用程序时,我根本没有收到任何通知。谁能给我提个建议吗。 我使用的平板电脑是: 运行在安卓4.4.2上的联想标签2 A7-20F 这是我的代码。 Projectbuild.gradle buildscript { ... dependencies { ... classpath 'com.google.gms:goog
我使用的平板电脑是:
运行在安卓4.4.2上的联想标签2 A7-20F
这是我的代码。
Projectbuild.gradle
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:3.0.0'
}
}
apply plugin: 'com.android.application'
...
dependencies {
...
compile 'com.google.firebase:firebase-messaging:10.0.1'
...
}
apply plugin: 'com.google.gms.google-services'
应用程序build.gradle
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:3.0.0'
}
}
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>
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);
}
}
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);
}
}
MyFirebaseMessagingService
<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>
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);
}
}
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开始。这些文档应该会有所帮助。从更新gms和Firebase开始。这些文件应该会有所帮助