Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sleaq.php;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Debug;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final EditText username = (EditText)findViewById(R.id.username);
- final EditText password = (EditText)findViewById(R.id.password);
- Button button = (Button)findViewById(R.id.btnLogin);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new Login().execute("http://www.sleaq.com/apps/416/login.php?username=" + username.getText().toString() + "&password=" + password.getText().toString());
- }
- });
- }
- public class Login extends AsyncTask<String, String, String>
- {
- @Override
- protected String doInBackground(String... params)
- {
- HttpURLConnection conn = null;
- try
- {
- URL url;
- url = new URL(params[0]);
- conn = (HttpURLConnection) url.openConnection();
- if (conn.getResponseCode() == HttpURLConnection.HTTP_OK)
- {
- InputStream is = conn.getInputStream();
- String response = convertStreamToString(is);
- if (response == "User existiert")
- {
- //next Activity starten
- }
- else
- {
- }
- }
- else
- {
- }
- return "Done";
- }
- catch (MalformedURLException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- finally
- {
- if (conn != null)
- {
- conn.disconnect();
- }
- }
- return null;
- }
- private String convertStreamToString(InputStream is)
- {
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- StringBuilder sb = new StringBuilder();
- String line = null;
- try
- {
- while ((line = reader.readLine()) != null)
- {
- sb.append(line).append('\n');
- }
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- return sb.toString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement