So, part of my application builds a line of navigation directions, and then tries to parse JSON and draw the polyline routes on my map. First, I build my string using Location variables or Locale constants. I get something like
https:
Festival, Durham, 27701&destination=601 W Peace St, Raleigh,27605&sensor=false&key={API_KEY}
- there is no new line (I added it for readability), and {API_KEY} is my actual api key.
The problem I am facing is that when I pass this url to this method downloadUrl (String urlString)
private String downloadUrl(String urlString) throws IOException {
Log.d(TAG, "Downloaded string = " + urlString);
String data = "";
InputStream stream = null;
HttpURLConnection urlConnection = null;
try {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(urlString));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
URL url = new URL(urlString);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.connect();
stream = urlConnection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
StringBuffer sb = new StringBuffer();
String line = "";
while ((line = br.readLine()) != null) {
Log.d(TAG,"url download stream: " + line);
sb.append(line);
}
data = sb.toString();
br.close();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
Log.d(TAG, "Downloaded data = " + data);
stream.close();
urlConnection.disconnect();
}
return data;
}
JSON displays correctly in my browser, I see everything as Google describes it in the documentation. But then in the following lines, when I try to open a connection to a URL and pull the JSON into a string for parsing, I get a System.err notification
05-02 09:56:01.540: W/System.err(32232): java.io.FileNotFoundException:
https:
Film Festival, Durham, 27701&destination=601 W Peace St, Raleigh, 27605&sensor=false&key={API_KEY}
, , , ( ) FNFE. , , ? , ? , .