데이터베이스에 토큰을 보내려고합니다. 그러나 내 데이터베이스는 토큰을받지 못합니다. 최종 OkHttpClient 클라이언트 = 새로운 OkHttpClient()가 스레딩 문제를 가지고 있다는 것을 알았습니다. 이 문제를 해결하는 방법? 최신 okhttp3 및 okio jar 파일을 사용하고 있습니다.최종 OkHttpClient 클라이언트에서의 멀티 스레딩 문제 = 새 OkHttpClient();
MyfirebaseInstanceIDService.java
package ******;
import android.util.Log;
import android.widget.Toast;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
import java.io.IOException;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG =
MyFirebaseInstanceIDService.class.getSimpleName();
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String token = FirebaseInstanceId.getInstance().getToken();
sendToken(token);
}
private void sendToken(String token) {
final OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder()
.add("token",token)
.build();
final okhttp3.Request request = new okhttp3.Request.Builder()
.url("******")
.post(body)
.build();
final Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
스택 트레이스
01-26 05:16:09.564: W/GLSUser(2025): [AppCertManager] IOException while
키 요청 : 01-26 05 : 16 : 09.564 : GLSUser/W (2025) : 때 java.io.IOException 잘못된 장치 응답 키는 입니다. 01-26 05 : 16 : 09.564 : W/GLSUser (2025) : 16 : 09.564 :
eka.a(:com.google.android.gms:271)
01-26 05:16:09.564: W/GLSUser(2025):
eka.a(:com.google.android.gms:4236)
01-26 05:16:09.564: W/GLSUser(2025): at ejz.a(:com.google.android.gms:46)
01-26 05:16:09.564: W/GLSUser(2025): at ejt.a(:com.google.android.gms:53)
01-26 05:16:09.564: W/GLSUser(2025): at ejs.a(:com.google.android.gms:111)
01-26 05:16:09.564: W/GLSUser(2025):at com.google.android.gms.auth.account.be.
legacy.AuthCronChimeraService.b
(:com.google.android.gms:4052)
01-26 05:16:09.564: W/GLSUser(2025):atdup.call(:com.google.android.gms:2043)
01-26 05:16:09.564: W/GLSUser(2025):a
java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-26 05에서 (2025) GLSUser/W : kmo.run (AT : com.google .android.gms : 450) 01-26 05 : 16 : 09.564 : W/GLSUser (2025) : java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133) 01-26 05 : 16 : 09.564 : W/GLSUser (2025) : ktt.run (: 2015)에서 W/GLSUser (2025) : W/GLSUser (2025) com// GLSUser (2025) : java.lang.Thread.run (Thread.java:761) 01-26 05:16 : 09.572 : W/ContentTaskController (2025) : Invali d newTask는 시작 추적에 제공된
입니다.