![](/img/trans.png)
[英]Convert org.restlet.data.MediaType to com.google.common.net.MediaType
[英]cannot resolve method create 'com.google.common.net.MediaType,java.lang.String)
我想使用OkHttp 3將設備發送到設備Firebase通知,但是發布JSON時出現以下錯誤:
cannot resolve method create 'com.google.common.net.MediaType,java.lang.String)
這是我的代碼:
final String legacyServerKey = "";
final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
OkHttpClient client = new OkHttpClient();
JSONObject json = new JSONObject();
JSONObject dataJson = new JSONObject();
dataJson.put("body", "Hi this is sent from device to device");
dataJson.put("title", "dummy title");
json.put("notification", dataJson);
json.put("to", reg_token);
RequestBody body = RequestBody.create(JSON, json.toString());
Request request = new Request.Builder()
.header("Authorization", "key=" + legacyServerKey)
.url("https://fcm.googleapis.com/fcm/send")
.post(body)
.build();
try {
Response response = client.newCall(request).execute();
String finalResponse = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
好像您導入了com.google.common.net.MediaType
。 您需要okhttp3.MediaType
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.