前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >fcm的java发送代码

fcm的java发送代码

作者头像
技巅
发布2018-05-25 14:12:26
1.1K0
发布2018-05-25 14:12:26
举报
文章被收录于专栏:技巅技巅

public static void send(String urlPath, String content) throws JSONException {         try {             URL url = new URL(urlPath);             HttpURLConnection connection = (HttpURLConnection) url.openConnection();             connection.setDoOutput(true);             connection.setDoInput(true);             connection.setRequestMethod(“POST”);             connection.setUseCaches(false);             connection.setInstanceFollowRedirects(true);             connection.setRequestProperty(“Content-Type”, “application/json”);             connection.setRequestProperty(“Authorization”, “”);             connection.connect();             DataOutputStream out = new DataOutputStream(connection.getOutputStream());             JSONObject json = new JSONObject();              json.put(“to”, “erUretmvVrM:APA91bEWrUIsl1KawvionLeu3YkBqrH2cYKoeAy7Pc16J7xZcNVwvzQKbPYc14K90YBcbysxkkFzr7HUKX7vj0T9XrDbD3uFsI7v4J3LZmtwiGe2PsK49JcnLyJMiYmFz3wnS9J6Ycot”);              JSONObject info = new JSONObject();             info.put(“title”, “Notificatoin Title”); //通知标题             info.put(“body”, “Hello Test notification”); // Notification body              json.put(“notification”, info);             out.writeBytes(json.toString());             out.flush();             out.close();             BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));             String lines;             StringBuffer sb = new StringBuffer(“”);             while ((lines = reader.readLine()) != null) {                 lines = new String(lines.getBytes(), “utf-8”);                 sb.append(lines);             }             System.out.println(sb);             reader.close();             // 断开连接             connection.disconnect();         } catch (MalformedURLException e) {             e.printStackTrace();         } catch (UnsupportedEncodingException e) {             e.printStackTrace();         } catch (IOException e) {             e.printStackTrace();         }

}

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年10月19日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档