Downloading A Website To A String
Having done some basic tutorials, I started making my first real android app in eclipse. I want this app to check if the text in an EditText matches the text on a website (this one
Solution 1:
You can get the text using InputStream Reader like this.
try
{
URLurl=newURL("http://yourwebpage.com");
// Read all the text returned by the serverBufferedReaderin=newBufferedReader(newInputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null)
{
// str is one line of text; readLine() strips the newline character(s)// You can use the contain method here.if(str.contains(editText.getText().toString))
{
You can perform your logic here!!!!!
}
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
Also add an additional permission in your apps Manifest file:
<uses-permission android:name="android.permission.INTERNET/>
//============================EDIT================================//
if (group.length() > 0)
{
mProgressDialog = newProgressDialog(this);
mProgressDialog.setMessage("Bezig met checken voor roosterwijzigingen...");
mProgressDialog.show();
try
{
URLurl=newURL("http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf");
BufferedReaderin=newBufferedReader(newInputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null){
if(str.contains(mEtxtGroup.getText().toString())){
if(mProgressDialog.isShowing())
{
mProgressDialog.dismiss();
}
Toast.makeText(this, "U hebt een roosterwijziging.", Toast.LENGTH_LONG).show();
break;
}
}
in.close();
} catch (MalformedURLException e) {
Toast.makeText(this, "Er is een fout opgetreden, probeer opniew.", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(this, "Er is een fout opgetreden, probeer opniew.", Toast.LENGTH_LONG).show();
}
if(mProgressDialog.isShowing())
{
mProgressDialog.dismiss();
}
}
else{
Toast.makeText(this, "Voer een klas in", Toast.LENGTH_LONG).show();
}
Solution 2:
This is a good related Java question: How do you Programmatically Download a Webpage in Java
You can then implement whatever method you choose into your app. One thing to note is that you will need to enable the INTERNET
permission on your app in order to access the internet.
Post a Comment for "Downloading A Website To A String"