gpt4 book ai didi

php - 安卓通知火力基地

转载 作者:行者123 更新时间:2023-11-29 14:30:00 26 4
gpt4 key购买 nike

我通过PHP向android发送通知,在android上正常。

但是当我发送多个时,它只显示最后一个,我希望它显示所有。

这可能吗?

我该怎么做?

PHP

$msg = array
(
'nome' => $comando,
);
$fields = array
(
'to' => $token,
'data' => $msg
);


$headers = array
(
'Content-Type: application/json',
'Authorization: key= KEY'
);

#Send Reponse To FireBase Server
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
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_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );

#Echo Result Of FireBase Server
echo $result;

安卓

Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410,
intent, PendingIntent.FLAG_UPDATE_CURRENT);

Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new
NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setSound(alert)
.setContentTitle("teste")
.setContentText("teste "+msg+"!")
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setPriority(2)
.setContentIntent(pendingIntent);

NotificationManager notificationManager =
(NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(1410, notificationBuilder.build());

最佳答案

很简单:

notificationManager.notify(1410, notificationBuilder.build());

你已经写了 '1410',而不是每次都分配 Unique_Integer_number。

To get unique no everytime:

Random random = new Random();
int m = random.nextInt(9999 - 1000) + 1000;

关于php - 安卓通知火力基地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47667749/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com