Android上解析Push JSON数据的问题

4

我对Android还比较陌生,希望你们能轻松解决我的问题!

我想让用户在按下应用程序上的按钮后向其他用户发送推送。我已经正确配置了ParsePush按钮点击监听器,因为这个功能很好:

            // Create our Installation query
            ParseQuery pushQuery = ParseInstallation.getQuery();
            pushQuery.whereEqualTo("installationId", installationId); //Send to targeted user

            // Send push notification to query
            ParsePush push = new ParsePush();
            push.setQuery(pushQuery); // Set our Installation query

            push.setMessage("HEY YOU");
            push.sendInBackground();

我想在推送中添加一个URI,于是我执行了以下操作:

                // Create our Installation query
            ParseQuery pushQuery = ParseInstallation.getQuery();
            pushQuery.whereEqualTo("installationId", installationId);

            // Send push notification to query
            ParsePush push = new ParsePush();
            push.setQuery(pushQuery); // Set our Installation query

            String string = "{\"title\" : \"my title\",\"alert\" : \"my alert text\",\"uri\" : \"myapp://host/path\"}";

            try {
                JSONObject data = new JSONObject(string);
                push.setData(data);
            } catch (JSONException e) {
                Log.e("MYAPP", "unexpected JSON exception", e);
            }

            push.sendInBackground();

在我的Android清单文件中,我有一个目标活动:

        <activity android:name=".Accept_Action">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="myapp" android:host="host" android:path="/path" />
        </intent-filter>
    </activity>

但是出于某些原因,这不起作用。 推送从未到达我的目标设备。 你能帮我让它起作用吗? 谢谢


1
是的,我知道,谢谢你关心。但我开始使用Parse,我的MVP几乎完成了,所以我想解锁这最后一部分。 而且,这实际上提高了我对Java和Android开发的整体知识水平。 - Eric NEMO
你在日志中看到了任何错误吗?你在解析界面上看到了推送的发送情况吗? - meynety
我的日志中没有错误,Parse Interface 中也没有通知 :/ @meynety - Eric NEMO
1个回答

1

回答您的问题

遗憾的是,出于安全原因,您不能从客户端使用解析推送的“uri”选项。

来源:

解决方案建议

我看到这个问题有两个可能的解决方案:

供学习参考

您可以通过实现sendInBackground()操作的回调来查看操作的实际结果,从而简单地查看此错误,如下所示:

push.sendInBackground(new SendCallback() {
            @Override
            public void done(ParseException e) {
                if (e != null) {
                    e.printStackTrace();
                } else {
                    Log.e("MYAPP", "Push sent.");
                }
            }
        });

因此,e.printStackTrace();会打印出上述错误115。
com.parse.ParseRequest$ParseRequestException: Client-initiated push cannot use the "uri" option

非常感谢您的帮助。让我测试一下,然后再回复您! - Eric NEMO
嘿@meynety,抱歉让你久等了。我现在正在按照建议开发云代码功能!感谢你的帮助! - Eric NEMO

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接