在Android中使用JSONObject发送带有“额外信息”的Firebase API通知

时间:2019-04-03 00:31:16

标签: android json firebase firebase-cloud-messaging http-post

我正在开发一个android应用,并且正在使用Firebase API通过HTTP POST在android studio中发送推送通知。我按照教程here发送标题和正文。工作正常。我想发送更多信息,请建议我如何实现?。这是我的代码:

fun = @(t) exp((-7).*abs(t)).*cos(10.*pi.*t);

a = @(k, T, t) fun(t).*cos((2.*pi.*k.*t)./(T));
b = @(k, T, t) fun(t).*sin((2.*pi.*k.*t)./(T));

T = 1; %T =0.5 - (-0.5) where T is fundamental period of x(t)

t = -0.5: T/1000: 0.5;

Kmax = 4; % part a

for k=1:Kmax
  ax = (2./T).*integral(@(t)a(k,T,t),0,T)
end

for k=1:Kmax
  a0 = (1./T).*integral(@(t)fun(t),0,T)
end

for k=1:Kmax
  bx = (2./T).*integral(@(t)b(k,T,t),0,T)
end

% Calcultating x_aprox

x_approx = a0;

for k=1:Kmax
  x_approx = x_approx + ax*cos(2*pi*k*t/T) + bx*sin(2*pi*k*t/T);
end

1 个答案:

答案 0 :(得分:0)

Firebase json有效负载如下:

[
    "to" => 'DEVICE_TOKEN',
    "notification" => [
        "body" => "SOMETHING",
        "title" => "SOMETHING",
        "icon" => "ic_launcher"
    ],
    "data" => [
        "ANYTHING EXTRA HERE"
    ]
]

使用以下内容作为附加功能。

JSONObject extras = new JSONObject();
extras.put("message", "Happy birthday!");
extras.put("userId", PreferenceUtils.getUserID());
json.put("data",extras);