我是 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”选项。
来源:
这篇博文 http://blog.parse.com/learn/android-push-gets-major-refresh/ :
As a security precaution, the uri option may not be used when a push is sent from a client.
来自解析文档中的错误部分 https://www.parse.com/docs/android/guide#errors-push-related-errors :
ClientPushWithURI 115 Client-initiated push cannot use the "uri" option.
解决方案建议
我看到这个问题有两种可能的解决方案:
- 从您从 Android 客户端调用的云代码函数 (https://www.parse.com/docs/cloudcode/guide#cloud-code-cloud-functions) 发送推送。
- 使用
uri
以外的名称并实现您自己的逻辑来处理它(覆盖ParsePushBroadcastReceiver
,示例:http://www.androidhive.info/2015/06/android-push-notifications-using-parse-com/)
用于学习目的
您可以简单地通过实现 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/