简体   繁体   English

如何将图像添加到来自 firebase 的 android 推送通知。 使用ionic 3开发

[英]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.

相关问题 我们如何使用Firebase云消息传递(fcm)在Android中发送推送通知来发送图像和图标 - How we can send image and icon by using Firebase cloud messaging(fcm) for push notification in android 带有来自服务器(php)的图像的 Android Firebase 推送通知未在通知中显示图像,而应用程序在后台 - Android Firebase Push Notification with image from server(php) not showing image in notification while app in background 使用PHP的Android Firebase推送通知 - Android Firebase Push notification using php Firebase Android推送通知 - Firebase push notification for android 如何使用 brozot / Laravel-FCM 在推送通知上添加图像 - How to add image on push notification using brozot / Laravel-FCM 如何使用GCM在Android中发送大小图像作为推送通知 - How to send small and large image as a push notification in android using GCM 如何显示来自Android推送通知中链接的图像? - How can I show an image from link in android push notification? 使用PHP向使用钛(跨平台)开发的Android应用程序发送推送通知 - Sending push-notification to android app developed in titanium (cross-platform) using PHP 如何使用触发器发送Firebase推送通知 - How to send firebase push notification using trigger Android Firebase推送通知未显示 - Android Firebase push notification not showing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM