首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >火势推送通知正在移动中,但不在平板电脑上。

火势推送通知正在移动中,但不在平板电脑上。
EN

Stack Overflow用户
提问于 2017-10-06 12:41:02
回答 1查看 466关注 0票数 1

我有一个非常基本的设置推送通知从防火墙和它的很好地工作在我的移动。在3到6秒内,我收到通知。同样的应用程序,当我试图在平板电脑上运行时,我根本没有收到任何通知。有人能给我点建议吗。

我使用的平板是:

联想TAB 2 A7-20F,运行在Android 4.4.2上

这是我的密码。

build.gradle项目

代码语言:javascript
运行
复制
buildscript {
    ...
    dependencies {
        ...
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

App build.gradle

代码语言:javascript
运行
复制
apply plugin: 'com.android.application'
...
dependencies {
    ...
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    ...
}
apply plugin: 'com.google.gms.google-services'

报表文件

代码语言:javascript
运行
复制
<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

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
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,我试着连接不同的网络,以防万一,事实证明,这是因为防火墙。办公室网络安装了防火墙,我的家庭网络没有防火墙。即使在移动数据上,它也运行得很好。

EN

回答 1

Stack Overflow用户

发布于 2017-10-06 12:48:52

从更新gms和Firebase开始。docs 这里应该会有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46605986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档