Faced a VERY strange problem, the answer to which I did not find in Google.
There is a task - using the Android application to download the html page and then work with it. It would seem that everything is fine, but the link contains Russian characters, so an empty html page is downloaded.
I take this Russian part of the page from EditText.
Link is being formed.
Download a blank page.
I read about this problem, everyone writes to use the transcoding of the Russian part in utf-8.
Recoded.
A blank page has been downloaded.
To check the link yourself, put the link text in this EditText.
I copy.
I pass on it through the browser on the smartphone - the link opens is correct!
But from the computer through the Chrome browser, it opens again empty. I tried to recode not only the Russian part, but the entire link - the problems remained.
I re-read all the forums, everyone is writing about utf-8, but it does not work, what should I do?
Method of extraction of the Russian part
private String getGroup () { EditText textEdit = (EditText) getView().findViewById(R.id.groupEditText); String group = textEdit.getText().toString(); return group; } Link forming method
private String getUrlString () { String firstURL = getString(R.string.url_first); String group = getGroup(); try { URLEncoder.encode(group, "utf-8"); } catch (UnsupportedEncodingException e) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.dialog_error); builder.setMessage(R.string.dialog_group_message); builder.setCancelable(true); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show(); } String secondURL = getString(R.string.url_second); String finaURL = firstURL + group + secondURL; return finaURL; } Just in case the connection method
URL url = new URL(timeTableURL); URLConnection connection = url.openConnection(); BufferedReader bufReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; createDir(getString(R.string.directory)); String fileName = getString(R.string.directory) + "/TimeTable" + timeTableGroup + ".html"; File file = new File(fileName); if (!file.exists()) { file.createNewFile(); } FileWriter fileWriter = new FileWriter(file.getAbsoluteFile()); BufferedWriter bufWriter = new BufferedWriter(fileWriter); while ((inputLine = bufReader.readLine()) != null) { bufWriter.write(inputLine); } bufWriter.close(); bufReader.close();