源代码如下:
String appId = "sHxob1bo1f7HGyGDOTjsVfqo-gzGzoHsz";
String appKey = "XXXXX"; // 这里隐藏了
String masterKey = "XXXXX"; // 这里隐藏了
AVOSCloud.initialize(appId, appKey, masterKey);
AVOSCloud.setDebugLogEnabled(true);
AVOSCloud.useAVCloudCN();
AVPush push = new AVPush();
JSONObject object = new JSONObject();
object.put("alert", "这是向 Android 设备直接推送的消息");
push.setPushToAndroid(true);
push.setData(object);
push.sendInBackground(new SendCallback() {
@Override
public void done(AVException e) {
if (e == null) {
// push successfully.
logger.info("send succ.");
} else {
// something wrong.
logger.error("send failed.{}", e);
}
}
});
收到了下面的错误:
00:20:57.734 [OkHttp https://api.leancloud.cn/1.1/push] ERROR com.bdj.server.common.utils.LeancloudUtils - send failed.{}
com.avos.avoscloud.AVException: 该操作已被禁止,请变更应用选项『禁止从客户端进行消息推送』。
at com.avos.avoscloud.AVErrorUtils.createException(AVErrorUtils.java:20) ~[leancloud-common-0.1.13.jar:?]
at com.avos.avoscloud.PostHttpResponseHandler.onSuccess(PostHttpResponseHandler.java:27) [leancloud-common-0.1.13.jar:?]
at com.avos.avoscloud.AsyncHttpResponseHandler.onResponse(AsyncHttpResponseHandler.java:40) [leancloud-common-0.1.13.jar:?]
at com.avos.avoscloud.okhttp.Call$AsyncCall.execute(Call.java:166) [okhttp-leancloud-2.6.0.jar:?]
at com.avos.avoscloud.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33) [okhttp-leancloud-2.6.0.jar:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
Process finished with exit code 0
虽然推送设置选项中开启了“禁止从客户端进行消息推送”, 但是我使用了mastkey,为啥还是不能推送呢?有人遇到过这个问题么?