android - 在 Android 上解析 Push JSON 数据问题

标签 android json parse-platform push-notification

我是 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 list 中,我有目标 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

关于android - 在 Android 上解析 Push JSON 数据问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35214661/

相关文章:

ios - PFObject 没有成员 objectforkey

swift - Swift 中从 Parse 到 UIPickerView 缺少数据

android - 想要在 ListView 中突出显示特定位置(必须从数据库中获取)

php - 在向 mysql 输入数据时删除额外的空间

json - Elasticsearch 观察器和 Microsoft Teams webhook

c# - 我可以通过一种方法在序列化(牛顿)中构建对象json吗?

c# - 如何将 JSON 数据发布到 MVC 4 Controller ?

java - 以编程方式滚动 ScrollView 以关注按钮或 View - Android

java - Android 的 BreakIterator 将换行符视为句子分隔符

ios - 无法将 channel 保存到 PFInstallation (iOS)