Android 上的解析推送 JSON 数据问题

Parse Push JSON data issue on Android

我是 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:

        <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>

但由于某种原因,这不起作用。推送永远不会落在我的目标设备上。 你能帮我完成这项工作吗? 谢谢

回答你的问题

遗憾的是,出于安全原因,您不能使用 "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