Better way of constructing url

Этот коммит содержится в:
Anton Tananaev
2016-11-05 19:54:31 +13:00
родитель b2f116b157
Коммит deba5e0a98
2 изменённых файлов: 3 добавлений и 4 удалений
-3
Просмотреть файл
@@ -60,9 +60,6 @@ public class MainFragment extends WebViewFragment {
String url = PreferenceManager.getDefaultSharedPreferences( String url = PreferenceManager.getDefaultSharedPreferences(
getActivity()).getString(MainActivity.PREFERENCE_URL, null); getActivity()).getString(MainActivity.PREFERENCE_URL, null);
if (url.endsWith("/")) {
url = url.substring(0, url.length() - 1);
}
getWebView().loadUrl(url); getWebView().loadUrl(url);
} }
+3 -1
Просмотреть файл
@@ -18,6 +18,7 @@ package org.traccar.manager;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Fragment; import android.app.Fragment;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@@ -63,7 +64,8 @@ public class StartFragment extends Fragment implements View.OnClickListener {
protected Boolean doInBackground(String... urls) { protected Boolean doInBackground(String... urls) {
try { try {
URL url = new URL(urls[0] + "/api/server"); Uri uri = Uri.parse(urls[0]).buildUpon().appendPath("api/server").build();
URL url = new URL(uri.toString());
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));