Loading website in line

With a few basic lessons, I started building my first eclipse Android app. I want this application to check if the text in the EditText matches the text on the website (this: http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf (it contains my school change schedule)). I learned how to make the application check if the text in the EditText matches the string (using the contains () method), so now the only thing I need to do is load all the text of this website into a string. But I have no idea how to do this. Or there may be a method that I can check if the website contains a specific word without loading the website text into a string.

Thanks!

(By the way, I'm not English, so I ask you to forgive me if I made some language mistakes.)

@androider I can not post my code in the comment field, here it is:

package me.moop.mytwitter; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import android.app.Activity; import android.app.ProgressDialog; public class MainActivity extends Activity { Button mBtnCheck; EditText mEtxtGroup; ProgressDialog mProgressDialog; TwitterUser mTwitterUser; TextView mTxtv1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.nicelayout3); mBtnCheck = (Button) findViewById(R.id.btnCheck); mEtxtGroup = (EditText) findViewById(R.id.etxtGroup); mTxtv1 = (TextView) findViewById(R.id.textView1); } public void checkScheduleChange(View view){ if (view == mBtnCheck){ String group; group = mEtxtGroup.getText().toString(); if (group.length() > 0){ mProgressDialog = new ProgressDialog(this); mProgressDialog.setMessage("Bezig met checken voor roosterwijzigingen..."); mProgressDialog.show(); try { URL url = new URL("http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String str; while ((str = in.readLine()) != null){ mProgressDialog.dismiss(); if(str.contains(mEtxtGroup.getText().toString())){ Toast.makeText(this, "U hebt een roosterwijziging.", Toast.LENGTH_LONG).show(); } else{ Toast.makeText(this, "U hebt geen roosterwijzigingen", Toast.LENGTH_LONG).show(); } } 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(); } } else{ Toast.makeText(this, "Voer een klas in", Toast.LENGTH_LONG).show(); } } } } 

Here are the properties of the button:

  <Button android:id="@+id/btnCheck" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:clickable="true" android:onClick="checkScheduleChange" android:text="Check" > 
+6
source share
2 answers

You can get text using an InputStream Reader like this.

 try { URL url = new URL("http://yourwebpage.com"); // Read all the text returned by the server BufferedReader in = new BufferedReader(new InputStreamReader(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 additional permission to the application manifest file:

 <uses-permission android:name="android.permission.INTERNET/> 

// ============================= EDIT ==================== ================

 if (group.length() > 0) { mProgressDialog = new ProgressDialog(this); mProgressDialog.setMessage("Bezig met checken voor roosterwijzigingen..."); mProgressDialog.show(); try { URL url = new URL("http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf"); BufferedReader in = new BufferedReader(new InputStreamReader(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(); } 
+5
source

This is a good Java related question: How do you programmatically load a web page in Java .

Then you can implement any method that you choose in your application. It should be noted that you need to enable INTERNET permission for your application in order to access the Internet.

+1
source

Source: https://habr.com/ru/post/921018/


All Articles