Cordova 如何将推送通知中的图片发送到ionic 2应用程序

Cordova 如何将推送通知中的图片发送到ionic 2应用程序,cordova,push-notification,ionic2,google-cloud-messaging,cordova-plugins,Cordova,Push Notification,Ionic2,Google Cloud Messaging,Cordova Plugins,我尝试使用以下代码将图片发送到我的android应用程序 public class PushNotificationUtility { private static String SERVER_KEY = "MYSERVERKEY"; public static void main(String[] args) throws Exception { String title = "My First Notification"; String m

我尝试使用以下代码将图片发送到我的android应用程序

public class PushNotificationUtility {

    private static String SERVER_KEY = "MYSERVERKEY";

    public static void main(String[] args) throws Exception {
        String title = "My First Notification";
        String message = "Hello, I'm push notification";
        sendPushNotification(title, message);
    }

    private static void sendPushNotification(String title, String message) throws Exception {
        // Create connection to send FCM Message request.
        URL url = new URL("https://fcm.googleapis.com/fcm/send");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Authorization", "key=" + SERVER_KEY);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);

        JSONObject json = new JSONObject();
        json.put("to","/topics/MYTopic");
        JSONObject info = new JSONObject();
        info.put("title", title); // Notification title
        info.put("body", message); // Notification body
        info.put("picture","http://36.media.tumblr.com/c066cc2238103856c9ac506faa6f3bc2/tumblr_nmstmqtuo81tssmyno1_1280.jpg");
        info.put("summaryText","Summary");
        json.put("notification", info);


        // Send FCM message content.
        OutputStream outputStream = conn.getOutputStream();
        outputStream.write(json.toString().getBytes());

        System.out.println(conn.getResponseCode());
        System.out.println(conn.getResponseMessage());
    }
}
我可以向Android设备发送通知,但不能发送图片。我想把照片和信息一起发送。在客户端,我需要做些什么来显示图片吗


如何解决此问题?

上没有
图片
属性,您可以使用
数据
属性发送重要数据,当用户收到推送时,使用属性
图片
通过图像链接创建它:

let data = {
  picture: 'http://36.media.tumblr.com/c066cc2238103856c9ac506faa6f3bc2/tumblr_nmstmqtuo81tssmyno1_1280.jpg'
};
info.put("data", data); // Notification data
在接收推送方法中,您可以获取此属性并显示图片

myPlugin.on('notification', notification => {
  console.log(notification); // JUST TO SEE THE CALLBACK STRUCTURE
  this.myImage = notification.data.picture;
});

希望这有帮助:D

上没有
图片
属性,您可以使用
数据
属性发送重要数据,当用户收到推送时,使用属性
图片
通过图像链接创建它:

let data = {
  picture: 'http://36.media.tumblr.com/c066cc2238103856c9ac506faa6f3bc2/tumblr_nmstmqtuo81tssmyno1_1280.jpg'
};
info.put("data", data); // Notification data
在接收推送方法中,您可以获取此属性并显示图片

myPlugin.on('notification', notification => {
  console.log(notification); // JUST TO SEE THE CALLBACK STRUCTURE
  this.myImage = notification.data.picture;
});

希望这有帮助:D

我希望图像作为通知的一部分显示,就像一些报价的广告一样。不是一些数据。通常我们会在购物应用程序中看到此类通知。@user1188867哦,明白了。据我所知,FCM cordova插件不支持此类通知。Ionic.io通知也不支持它。我认为这是更原生的,或者还没有人能够用插件做到这一点。但这里有一个关于如何实现这一点的Android教程,我希望图像作为通知的一部分显示出来,就像一些产品的广告一样。不是一些数据。通常我们会在购物应用程序中看到此类通知。@user1188867哦,明白了。据我所知,FCM cordova插件不支持此类通知。Ionic.io通知也不支持它。我认为这是更原生的,或者还没有人能够用插件做到这一点。但这里有一个关于如何实现这一点的Android教程