我对
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 Manifest中,我有一个有针对性的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