Php Android应用程序未在应用程序外部振动
我有一个小问题:如果我从web上通过php向我的android设备发送通知,会生成一个通知,但不会在应用程序外振动。只有当我在应用程序中时,它才会振动 这是我的密码: PHP: 我无法在线获得任何修复,因此我在这里询问。 我是这么说的,振动在起作用,但只在应用程序内部。如果我关闭它,即使不停止进程,它也只显示通知,不会振动或显示正确的徽标Php Android应用程序未在应用程序外部振动,php,android,Php,Android,我有一个小问题:如果我从web上通过php向我的android设备发送通知,会生成一个通知,但不会在应用程序外振动。只有当我在应用程序中时,它才会振动 这是我的密码: PHP: 我无法在线获得任何修复,因此我在这里询问。 我是这么说的,振动在起作用,但只在应用程序内部。如果我关闭它,即使不停止进程,它也只显示通知,不会振动或显示正确的徽标 是否调用了第一个检查displayNotification。没有人打电话。如果您正在使用FCM,请参阅。在生成通知之前唤醒cpu。例如:PowerManag
是否调用了第一个检查
displayNotification
。没有人打电话。如果您正在使用FCM,请参阅。在生成通知之前唤醒cpu。例如:PowerManager PowerManager=(PowerManager)getSystemService(POWER\u服务);WakeLock WakeLock=powerManager.newWakeLock(powerManager.PARTIAL_WAKE_LOCK,“MyWakelockTag”);wakeLock.acquire()@ADM它可能不会被调用,但当我在应用程序中时,振动被使用。
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;
}
public class MyNotificationManager {
private Context mCtx;
private static MyNotificationManager mInstance;
private MyNotificationManager(Context context){
mCtx=context;
}
public static synchronized MyNotificationManager getInstance(Context context){
if(mInstance== null){
mInstance = new MyNotificationManager(context);
}
return mInstance;
}
public void displayNotification(String title, String body){
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx, Constants.CHANNEL_ID)
.setSmallIcon(R.drawable.sirenlight)
.setContentTitle(title)
.setVibrate(new long[] {0, 5000, 100, 5000, 100, 5000, 100, 5000, 100, 5000, 100, 5000})
.setContentText(body);
Intent intent = new Intent(mCtx, EinsatzInterface.class);
PendingIntent pendingIntent = PendingIntent.getActivity(mCtx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pendingIntent);
NotificationManager mNotificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
if(mNotificationManager!=null){
mNotificationManager.notify(1, mBuilder.build());
}
}
}