From deba5e0a98bfed80d48630b4ebc81480d68d9ec6 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 5 Nov 2016 19:54:31 +1300 Subject: Better way of constructing url --- app/src/main/java/org/traccar/manager/MainFragment.java | 3 --- app/src/main/java/org/traccar/manager/StartFragment.java | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/traccar/manager/MainFragment.java b/app/src/main/java/org/traccar/manager/MainFragment.java index 0fd79d1..d63c19e 100644 --- a/app/src/main/java/org/traccar/manager/MainFragment.java +++ b/app/src/main/java/org/traccar/manager/MainFragment.java @@ -60,9 +60,6 @@ public class MainFragment extends WebViewFragment { String url = PreferenceManager.getDefaultSharedPreferences( getActivity()).getString(MainActivity.PREFERENCE_URL, null); - if (url.endsWith("/")) { - url = url.substring(0, url.length() - 1); - } getWebView().loadUrl(url); } diff --git a/app/src/main/java/org/traccar/manager/StartFragment.java b/app/src/main/java/org/traccar/manager/StartFragment.java index 6d41fb2..429e8d1 100644 --- a/app/src/main/java/org/traccar/manager/StartFragment.java +++ b/app/src/main/java/org/traccar/manager/StartFragment.java @@ -18,6 +18,7 @@ package org.traccar.manager; import android.app.AlertDialog; import android.app.Fragment; import android.content.DialogInterface; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; @@ -63,7 +64,8 @@ public class StartFragment extends Fragment implements View.OnClickListener { protected Boolean doInBackground(String... urls) { 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(); BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); -- cgit v1.2.3