Android 解析仪表板中的“推送已发送 0”

问题描述 投票:0回答:2

我正在尝试将推送通知从解析发送到android。从浏览器发送数据时,设备的计算结果会正确显示。但浏览器中却显示“Pushes sent 0”。

我在应用程序类中注册通知

ParsePush.subscribeInBackground("", new SaveCallback() {
    @Override
    public void done(ParseException e) {
        if (e == null) {
            Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
        } else {
            Log.e("com.parse.push", "failed to subscribe for push", e);
        }
    }
});
ParseInstallation.getCurrentInstallation().saveInBackground();

我还在我的android项目中创建了

Receiver

public class PushMessageBroadcast extends ParsePushBroadcastReceiver {

    @Override
    public void onPushOpen(Context context, Intent intent) {
        Log.d("The push","open");
    }

    @Override
    protected Notification getNotification(Context context, Intent intent) {
        // TODO Auto-generated method stub
        return super.getNotification(context, intent);
    }

    @Override
    protected void onPushDismiss(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onPushDismiss(context, intent);
    }

    @Override
    protected void onPushReceive(Context context, Intent intent) {
        //here You can handle push before appearing into status e.g if you want to stop it.
        super.onPushReceive(context, intent);
    }
}

我还对清单进行了更改:

<receiver
    android:name=".receivers.PushMessageBroadcast "
    android:exported="false">
    <intent-filter>
        <action android:name="com.parse.push.intent.RECEIVE" />
        <action android:name="com.parse.push.intent.DELETE" />
        <action android:name="com.parse.push.intent.OPEN" />
    </intent-filter>
</receiver>

我需要更改解析中的任何设置吗?预先感谢。

java android parse-platform push-notification
2个回答
1
投票

编辑答案

在 @lochana-tejas 评论后,我意识到我的答案不正确,因为我在 Google 开发者控制台“Cloud Messaging for Android”中再次禁用,而我的设备无论如何都收到了通知。

因此,您需要控制的第一件事是在 Parse Dashboard 中,您有类 Installation 并且该类注册了一个或多个设备。如果您没有此类或为空,“发送的推送”将为 0。

我在这里复制我的代码,以便您可以比较

  public static void registerParse(Context context) {
        Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);

        Parse.initialize(context, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
        ParseInstallation.getCurrentInstallation().saveInBackground();

        ParsePush.subscribeInBackground(PARSE_CHANNEL, new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (e == null) {
                    Log.d("com.parse.push", "Successfully subscribed to Parse!");
                } else {
                    Log.e("com.parse.push", "failed to subscribe for push", e);
                }
            }
        });
    }

    //This is the user that will be inserted in "Installation class"
    public static void subscribeWithUser(String user) {
        ParseInstallation installation = ParseInstallation.getCurrentInstallation();

        installation.put("user", user);

        installation.saveInBackground(new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (e == null) {
                    Log.e("subscribeWithUser", "User subscribed successfully!!", e);
                } else {
                    e.printStackTrace();
                    Log.e("subscribeWithUser", "Error to save user", e);
                }
            }
        });


    }

我的清单是这样的

        <!-- Added for Parse push notifications -->

        <service android:name="com.parse.PushService" />
        <receiver
            android:name=".receiver.CustomPushReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.parse.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.parse.starter" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.ParseBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>   

0
投票

使用 FlutterFlow 和 Firebase 创建和配置移动应用程序可能是一个真正的挑战,尤其是在将应用程序迁移到不同的 Firebase 服务器或解决发送推送通知的问题时。本文将介绍成功解决这些任务的关键步骤。

将您的应用程序迁移到不同的 Firebase 服务器 检查 SHA-1 和 SHA-256 签名

第一步是确保 Google Play 和 Firebase 之间的 SHA-1 和 SHA-256 签名匹配。在通过 FlutterFlow 自动配置 Firebase 的过程中,这些签名可能会被更改,因此在部署之前从 Firebase 下载原始文件并验证 SHA-1 和 SHA-256 签名是否正确至关重要。

服务器位置匹配

第二个重要方面是检查服务器位置。如果您选择了欧洲的服务器(例如“europe-west1”),请确保在 FlutterFlow 中设置相同的服务器位置。服务器位置的差异可能会导致意外问题。

解决推送通知问题 在 Google Cloud Console 中检查 FCM API 设置

第三步涉及在 Google Cloud Console 中检查 Firebase Cloud Messaging (FCM) API 的设置。必须确保 FCM API 已启用并且在 Firebase 控制台中显示密钥。如果未显示该密钥,您需要在 Google Cloud Console 中创建一个新密钥。

删除 Firebase 中自动创建的函数

在完成推送通知设置之前,请删除 Firebase 中 FlutterFlow 创建的所有函数。返回 FlutterFlow,启用推送通知设置,然后继续部署,确保服务器位置配置正确。

重要提醒 请勿重新配置 Firebase 文件,因为这可能会导致在 Firebase 中向您的应用添加新的 SHA-1 和 SHA-256 密钥。 确保您已为 [email protected](服务帐户用户、编辑者、云功能管理员)分配正确的角色。 按照这些步骤(我个人花了大约一个月的时间)后,我成功发布了更新的应用程序。部署后大约 12 小时,推送通知开始到达,并且 FCM 令牌开始添加到 Firebase 中的用户集合中。如果您没有看到 fcm_tokens 子集合,请尝试注销并重新登录以创建它。

我希望这些信息对您有所帮助。如果您还有任何疑问或需要咨询,我很乐意为您提供支持。请写信给我 [电子邮件受保护]

结论 成功将您的应用迁移到不同的 Firebase 服务器并解决推送通知问题需要注意细节并遵守特定程序。通过以下步骤,您可以将风险降到最低,保证您的应用稳定运行。

© www.soinside.com 2019 - 2024. All rights reserved.