我有一个小问题:如果我通过网络上的php向我的Android设备发送通知,则会建立通知,但不会在应用程序外振动。当我进入应用程序时,它只会振动。
以下是我的代码:
PHP:
//disordered products.
var products = [{
primaryName: 'test'
},
{
name: 'test7'
},
{
primaryName: 'test3'
},
{
name: 'test4'
},
{
name: 'test5'
},
{
primaryName: 'test1'
},
{
primaryName: 'test2'
},
{
name: 'test6'
},
]
var filtered = products.map(function(product) {
var universalName = product['primaryName'] || product['name'];
product.universalName = universalName;
return product;
})
.sort(function(a, b) {
return a['universalName'].localeCompare(b['universalName']);
});
//ordered by universalName;
console.log(filtered);
我的Android通知代码:
function send_notification ($token, $message, $Raum, $Notruf){
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array('to' => $token, 'notification' => array('body' => "Raum ".$Raum.", Notruf ".$Notruf), 'data' => array ('message' => $message));
$headers = array ('Authorization:key = (HERE IS MY AUTH KEY)','Content-Type: application/json');
$ch = curl_init ();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result == FALSE) {
die ('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
$sql = 'SELECT token FROM devices as d, Sani as s WHERE d.sean = s.sean AND s.Status!=0';
$result = mysqli_query($db, $sql);
$tokens = array ();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)){
$tokens[] = $row["token"];
}
}
mysqli_close($db);
$message = array ("message" => "Raum ".$Raum.", Notruf ".$Notruf);
for ($i = 0; $i < count($tokens); ++$i) {
$message_status = send_notification ($tokens[$i], $message, $Raum, $Notruf);
echo $message_status;
}
我无法在线获得任何修复,所以我在这里问。 我怎么说,振动是有效的,但只在应用程序内部。如果我关闭它,即使没有停止过程,它也只显示通知,不会振动或显示正确的徽标。
When inside the app the notification looks like this (vibrating and icon showing):
When outside the app the notification looks like this (not vibrating and icon not showing):