0
私はアンドロイドアプリに画像を送るために次のコードを試してみました。イオン2アプリにプッシュ通知で画像を送る方法
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デバイスに送信できますが、画像は送信できません。私はメッセージと共に絵を送っていきたいです。画像を表示するためにクライアント側で何かしなければならないことはありますか?
この問題を解決するにはどうすればよいですか?
私は画像だけでいくつかのオファーの広告のような通知の一部として表示させたいです。いくつかのデータではありません。通常、これらの通知はショッピングアプリで表示されます。 – user1188867
このようなものhttps://i.stack.imgur.com/5p4pa.png – user1188867
@ user1188867ああ、それを得た。私が知る限り、FCM cordovaプラグインはこの種の通知をサポートしていません。 Ionic.ioの通知もサポートしていません。私はこれがネイティブだと思うし、プラグインでこれをやっている人もいない。しかし、これはどのようにこのhttp://androidbash.com/firebase-push-notification-android/を達成するためのAndroidのチュートリアルです –