I am currently trying to make an app that would allow you to log into your account and view whatever data needs to be displayed.
I am not using webview but instead, for displaying information I will be parsing data from HTML and then working from there, extracting data that I need to display. I will post code from my app below.
What I need help with is figuring out how to log into the website with my app.
Basically, steps would look like that:
1.Enter Username
2.Enter Password
3.Press Login Button
4.Send Username&Password to the website
5.If - website returns "Successful login", proceed and parse next page from HTML, Else - display "Wrong username or password"
However, I have no idea how to make my app log in, or at least input data in the website's login fields so that I can at least get a response in some way.
I am very new to this, so please, at least point me in the right direction so that I can figure it out. Thank you very much.
package com.example.app;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class MainActivity extends AppCompatActivity {
String data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView LoginTitle = findViewById(R.id.tvLoginTitle);
EditText Username = findViewById(R.id.etUsername);
EditText Password = findViewById(R.id.etPass);
Button Login = findViewById(R.id.btLogin);
Login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Parse().execute();
Intent intent = new Intent(MainActivity.this,UserAccount.class);
intent.putExtra("data",data);
startActivity(intent);
}
});
}
public class Parse extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
try {
Document WebPage = Jsoup.connect("https://myurl").get();
Log.d("data", WebPage.toString());
data=WebPage.toString();
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
//Used in guide, however, my implementation of the app doesn't seem to need this.
}
}
}