[英]How to add image to android push notification from firebase. developed using ionic 3
I want to add an image to push notification.我想添加一个图像来推送通知。 am using firebase and app is developed using ionic 3 frameworks.
我正在使用 firebase,应用程序是使用 ionic 3 框架开发的。 I have a web app to push the notification.
我有一个网络应用程序来推送通知。 this is the PHP code.
这是PHP代码。 Please help me to add an image to push notification.
请帮我添加图像以推送通知。
public function pushNotification($title, $body, $image) { //FCM API end-point $url = 'https://fcm.googleapis.com/fcm/send'; //api_key available in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key $server_key = 'xxxx'; $target = []; $targets = $this->db->get('device_ids')->result(); foreach($targets as $val) { array_push($target, $val->device_id); } $fields = array(); $fields['notification'] = array( 'title' => $title, 'body' => $body ); if(is_array($target)){ $fields['registration_ids'] = $target; }else{ $fields['to'] = 'news'; } //header with content_type api key $headers = array( 'Content-Type:application/json', 'Authorization:key='.$server_key ); //CURL request to route notification to FCM connection server (provided by Google) $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_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); if ($result === FALSE) { die('Oops! FCM Send Error: ' . curl_error($ch)); } curl_close($ch); print_r(json_encode($fields)); }
$tokenListAndroid = "YOUR_TOKEN";
define( 'API_ACCESS_KEY', 'YOUR_KEY');
$Message='YOUR_MESSAGE';
$offerId=$_POST['offerId'];
$iOSids = explode(",",$tokenListiOS);
$androidIds = explode(",",$tokenListAndroid);
$msg = array
(
'title' => 'TEXT',
'message' => 'TEXT',
'summaryText' => 'TEXT',
'orderId' => 'TEXT',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'image' => 'YOUR_ICON_PATH ex. https://carboncostume.com/wordpress/wp-content/uploads/2016/08/blackpanther.jpg',
'style' => 'picture',
'picture' => 'YOUR_IMAGE_PATH ex. https://carboncostume.com/wordpress/wp-content/uploads/2016/08/blackpanther.jpg',
//'ongoing' => true,
'vibrate' => 1,
'sound' => 1
);
$fields = array
(
'registration_ids' => $androidIds,
'data' => $msg
);
//echo json_encode( $fields ); die;
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
Thats all XD就是这样XD
This is for IONIC 3 notification with Image and Text from firebase Implement Phonegap Push Plugin and create your firebase project ionic cordova plugin add phonegap-plugin-push //Now we send the Notification Post service这是用于带有来自 firebase 的图像和文本的 IONIC 3 通知实现 Phonegap Push Plugin 并创建您的 firebase 项目 ionic cordova plugin add phonegap-plugin-push //现在我们发送 Notification Post 服务
URL=https://fcm.googleapis.com/fcm/send
Header: Authorization: key={Your Firebase Key}
Content-Type: application/json
then send Body Body:然后发送身体身体:
***
{
"to": "/topics/college",
"data": {
"title": "Notification With Image",
"message": "This is my Notification with Image",
"style": "picture",
"picture": https://appsolzone.com/wp-content/uploads/2018/07/Scholar-Wings-2-480x336.jpg",
"summaryText": "This is image notification with Firebase in IONIC"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.