您能否确保其中的值userId
是您帐户上的有效 OneSignal id 并且已订阅?
您也可以改用以下代码来添加 logcat 日志记录以调试问题。
try {
OneSignal.postNotification(new JSONObject("{'contents': {'en':'Test Message'}, 'include_player_ids': ['" + "userId" + "']}"),
new OneSignal.PostNotificationResponseHandler() {
@Override
public void onSuccess(JSONObject response) {
Log.i("OneSignalExample", "postNotification Success: " + response.toString());
}
@Override
public void onFailure(JSONObject response) {
Log.e("OneSignalExample", "postNotification Failure: " + response.toString());
}
});
} catch (JSONException e) {
e.printStackTrace();
}