增加网络调试信息

0515
panqihua 5 years ago
parent 82a5f22852
commit 4eb0edaab6
  1. 2
      app/src/main/AndroidManifest.xml
  2. 2
      app/src/main/java/com/community/pocket/ui/login/LoginActivity.java
  3. 36
      app/src/main/java/com/community/pocket/util/HttpUtil.java
  4. 1
      app/src/main/java/com/community/pocket/util/InitApp.java
  5. 2
      app/src/main/res/values-en-rUS/strings.xml
  6. 2
      app/src/main/res/values-zh-rCN/strings.xml
  7. 2
      app/src/main/res/values/strings.xml

@ -10,7 +10,7 @@
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".ui.main.ui.forum.data.ForumDataActivity" />
<activity android:name=".ui.main.MainMenu" />
<activity android:name=".ui.resetpwd.ResetPwdActivity" />

@ -107,6 +107,7 @@ public class LoginActivity extends BaseActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HttpUtil.checkServer(this);
loginViewModel = new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(LoginViewModel.class);
@ -195,6 +196,7 @@ public class LoginActivity extends BaseActivity {
public void onParseOk(@NotNull Call call, @NotNull okhttp3.Response response, LoginResponse loginResponse) {
loginViewModel.getCheckToken().postValue(loginResponse);
}
}),
new FormBody.Builder()
.add("token", currentToken.getToken())

@ -1,9 +1,17 @@
package com.community.pocket.util;
import android.content.Context;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import com.community.pocket.BuildConfig;
import com.community.pocket.R;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -14,6 +22,7 @@ import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class HttpUtil {
@ -43,6 +52,33 @@ public class HttpUtil {
call.enqueue(callback);
}
//检查服务端连接
public static void checkServer(final Context context) {
//1.创建OkHttpClient对象
OkHttpClient okHttpClient = new OkHttpClient();
//2.创建Request对象,设置一个url地址(百度地址),设置请求方式。
Request.Builder builder = new Request.Builder().url(BuildConfig.API_HOST);
//3.创建一个call对象,参数就是Request请求对象
Call call = okHttpClient.newCall(builder.build());
//4.请求加入调度,重写回调方法
call.enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
if (BuildConfig.DEBUG) {
Looper.prepare();
new AlertDialog.Builder(context)
.setMessage(context.getString(R.string.check_server_fail, BuildConfig.API_HOST)).show();
Looper.loop();
}
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) {
}
});
}
public enum Method {
GET,
POST

@ -47,4 +47,5 @@ public class InitApp extends Application {
LocalManageUtil.saveSystemCurrentLanguage(getApplicationContext(), newConfig);
MultiLanguage.onConfigurationChanged(getApplicationContext());
}
}

@ -175,4 +175,6 @@
<string name="forum_status_ok">check ok</string>
<string name="forum_status_fail">check fail</string>
<string name="forum_status_uncheck">uncheck</string>
<string name="check_server_ok">connect server ok</string>
<string name="check_server_fail">connect server:%1s fail</string>
</resources>

@ -175,4 +175,6 @@
<string name="forum_status_ok">审核通过</string>
<string name="forum_status_fail">审核不通过</string>
<string name="forum_status_uncheck">未审核</string>
<string name="check_server_ok">连接服务端成功</string>
<string name="check_server_fail">调试信息:无法连接到服务端:%1s</string>
</resources>

@ -176,6 +176,8 @@
<string name="forum_status_ok">check ok</string>
<string name="forum_status_fail">check fail</string>
<string name="forum_status_uncheck">uncheck</string>
<string name="check_server_ok">connect server ok</string>
<string name="check_server_fail">connect server:%1s fail</string>
<!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save