MainActivity.java
import android.content.Intent; import android.os.Bundle; import android.os.Looper; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private EditText txt_username, txt_password; private Button btn_login; private String uriAPI = "http://study.ar-leung.net/android/index.php"; Intent intent = new Intent(); Bundle bundle = new Bundle(); @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txt_username = (EditText) findViewById(R.id.txt_username); txt_password = (EditText) findViewById(R.id.txt_password); btn_login = (Button) findViewById(R.id.btn_login); btn_login.setOnClickListener(sendlistener); } public View.OnClickListener sendlistener = new View.OnClickListener(){ public void onClick(View v){ if (v == btn_login){ if (txt_username != null && txt_password != null){ Thread thread = new Thread(new Runnable() { public void run() { try { JSONObject obj = sendPostDataToInternet(); System.out.println(obj.getString("username")); System.out.println(obj.getString("password")); if(obj.getString("status").equals("success")) { // Bundle - Store date to other activity bundle.putString("username", obj.getString("username")); bundle.putString("password", obj.getString("password")); intent.putExtras(bundle); intent.setClass(MainActivity.this, Transaction.class); startActivity(intent); MainActivity.this.finish(); }else{ Looper.prepare(); Toast.makeText(MainActivity.this, "Login Fail", Toast.LENGTH_SHORT).show(); Looper.loop(); } } catch (JSONException e) { e.printStackTrace(); } }}); thread.start(); } } } }; private JSONObject sendPostDataToInternet(){ HttpPost httpRequest = new HttpPost(uriAPI); List params = new ArrayList(); params.add(new BasicNameValuePair("username", txt_username.getText().toString())); params.add(new BasicNameValuePair("password", txt_password.getText().toString())); try{ httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); if (httpResponse.getStatusLine().getStatusCode() == 200){ // Get php string String strResult = EntityUtils.toString(httpResponse.getEntity()); Log.d("JSON", strResult); // String to JSON Object JSONObject obj = new JSONObject(strResult); return obj; } else{ Log.d("error", "no message"); } } catch (ClientProtocolException e){ Log.d("@@", e.toString()); } catch (IOException e){ Log.d("@@", e.toString()); } catch (Exception e){ Log.d("@@", e.toString()); } return null; } }
Transaction.java
import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.Button; public class Transaction extends AppCompatActivity { private Button btn_back; Intent intent = new Intent(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_transaction); Bundle bundle = getIntent().getExtras(); // Extract the data String username = bundle.getString("username"); String password = bundle.getString("password"); Log.d("username", username); Log.d("pasword", password); btn_back = (Button) findViewById(R.id.btn_back); btn_back.setOnClickListener(sendlistener); } public View.OnClickListener sendlistener = new View.OnClickListener(){ public void onClick(View v) { intent.setClass(Transaction.this, MainActivity.class); startActivity(intent); Transaction.this.finish(); } }; }
AndoridManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.leung.lbms"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Transaction"></activity> </application> </manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.leung.lbms.MainActivity" tools:layout_editor_absoluteY="81dp"> <TextView android:id="@+id/label_username" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:text="Username" android:textSize="24sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <EditText android:id="@+id/txt_username" android:layout_width="204dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginRight="16dp" android:layout_marginTop="16dp" android:ems="10" android:inputType="textPersonName" android:text="leung" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/label_password" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginTop="32dp" android:text="Password" android:textSize="24sp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/label_username" /> <EditText android:id="@+id/txt_password" android:layout_width="206dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginRight="16dp" android:layout_marginTop="16dp" android:ems="10" android:inputType="textPassword" android:text="password" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/label_username" /> <Button android:id="@+id/btn_login" android:layout_width="258dp" android:layout_height="44dp" android:layout_marginEnd="16dp" android:layout_marginStart="16dp" android:layout_marginTop="33dp" android:text="Login" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/txt_password" /> </android.support.constraint.ConstraintLayout>
activity_transaction.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.leung.lbms.Transaction"> <Button android:id="@+id/btn_back" android:layout_width="155dp" android:layout_height="wrap_content" android:layout_marginStart="112dp" android:layout_marginTop="76dp" android:text="Back" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <android.support.constraint.Guideline android:id="@+id/guideline" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_begin="20dp" /> </android.support.constraint.ConstraintLayout>
index.php
<?php header("Content-type: application/json; charset=utf-8"); if($_POST){ $str = '{"username":"'.$_POST['username'].'","password":"'.$_POST['password']; if($_POST['username'] == "leung" && $_POST['password'] == "password"){ $str .= '","status":"success"}'; }else{ $str .= '","status":"fail"}'; } echo $str; } ?>
Pingback: Free viagra
Pingback: generic cialis
Pingback: cialis generic name
Pingback: cialis 20 mg
Pingback: Buy viagra in canada
Pingback: Canada meds viagra
Pingback: cialis coupon walmart
Pingback: cialis price walmart
Pingback: cialis otc
Pingback: cialis 5 mg
Pingback: when will generic cialis be available
Pingback: online pharmacy viagra
Pingback: viagra for sale
Pingback: viagra generic
Pingback: best ed pills at gnc
Pingback: ed medication
Pingback: ed pills for sale
Pingback: cvs pharmacy
Pingback: Get cialis
Pingback: levitra online
Pingback: vardenafil coupon
Pingback: wind creek casino online play
Pingback: real money casino games
Pingback: sildenafil dosage
Pingback: best online casino real money
Pingback: pala casino online
Pingback: generic tadalafil
Pingback: cash loans
Pingback: personal loans
Pingback: quick cash loans
Pingback: viagra cost
Pingback: new cialis
Pingback: buy cialis
Pingback: buy cialis
Pingback: 5 mg cialis
Pingback: cialis buy
Pingback: gambling casino
Pingback: casino slot games
Pingback: best online casino
Pingback: play for real online casino games
Pingback: viagra cost
Pingback: viagra from india
Pingback: cheap viagra online canadian pharmacy
Pingback: cialis online reviews
Pingback: viagra vs cialis
Pingback: online casinos real money
Pingback: free casino games
Pingback: viagra without a doctor prescription
Pingback: buy sildenafil
Pingback: buy viagra generic
Pingback: cialis coupon 2020
Pingback: sildenafil
Pingback: canadian drugs pharmacy
Pingback: best canadian pharmacy
Pingback: viagra achat en france
Pingback: cialis
Pingback: viagra
Pingback: buy cialis online
Pingback: cheap viagra
Pingback: carprofen without vet prescription
Pingback: buy viagra generic
Pingback: Cheap Erection Pills
Pingback: buy tadalafil
Pingback: cialis 20mg pills
Pingback: 5mg cialis
Pingback: au cialis
Pingback: buy amoxicillin online cheap
Pingback: cialis order
Pingback: instant online payday loans
Pingback: Canadian viagra and healthcare
Pingback: where can i buy levitra online
Pingback: Viagra 100 mg
Pingback: law school essay writing service
Pingback: Buy viagra in us
Pingback: leg pain with cialis
Pingback: thesisbyd.com
Pingback: viagra experiences
Pingback: i need help writing an argumentative essay
Pingback: what is a good essay writing service
Pingback: dissertation proposal help
Pingback: essay custom writing
Pingback: professional research paper writers
Pingback: who will write my paper for me
Pingback: write thesis
Pingback: viagra over the counter usa 2020
Pingback: generic cialis order online
Pingback: Pfizer viagra 50mg
Pingback: viagra prices
Pingback: online pharmacy canada
Pingback: buy Amoxil
Pingback: ed doctors
Pingback: order cialis in australia
Pingback: how long does cialis take to work
Pingback: cialis 20 mg
Pingback: cialis pill
Pingback: viagra 100mg
Pingback: buy generic viagra
Pingback: prescription drugs from canada
Pingback: zithromax buy online no prescription
Pingback: cheap generic viagra
Pingback: buy generic viagra
Pingback: over the counter erectile dysfunction pills
Pingback: canadian discount pharmacy
Pingback: my canadian pharmacy
Pingback: Aciclovir for sale
Pingback: canadian pharmacy review
Pingback: shoppers drug mart canada
Pingback: fda approved canadian online pharmacies
Pingback: online pharmacy canada
Pingback: viagra
Pingback: generic viagra online
Pingback: how to get zithromax online
Pingback: how much is amoxicillin
Pingback: 10 mg benadryl tablets
Pingback: periactin 4mg online
Pingback: buy generic 100mg viagra online
Pingback: cheap generic viagra
Pingback: zithromax 500 mg lowest price drugstore online
Pingback: amoxicillin 500 mg cost
Pingback: canadian drugs without prescription
Pingback: sildenafil
Pingback: cialis with dapoxetine (generic)
Pingback: 800 mg cialis
Pingback: cialis coupon
Pingback: where to get the best price on cialis
Pingback: cheap cialis
Pingback: prescription viagra without a doctor
Pingback: kupi online cialis
Pingback: buy cialis united kingdom
Pingback: sildenafil 100mg purchase
Pingback: cheapest generic cialis australia
Pingback: generic viagra
Pingback: generic cialis
Pingback: buy cialis tadalafil tablets
Pingback: natural ed medications
Pingback: gnc ed pills
Pingback: mvuiiess
Pingback: erection pills that work
Pingback: best ed treatment pills
Pingback: what is viagra for
Pingback: buy cialis philippines
Pingback: waar kan ik viagra kopen
Pingback: best place to buy generic viagra online
Pingback: how long does zithromax work in your system
Pingback: furosemida
Pingback: vantin online
Pingback: buy doxycycline generic
Pingback: buy cephalexin online
Pingback: can i buy cialis online
Pingback: buy cialis online
Pingback: is cialis generic available
Pingback: farmacia viagra
Pingback: buy cialis 36 hour
Pingback: uk custom essay writing service
Pingback: free research paper writer
Pingback: i need someone to write my essay
Pingback: help me edit my essay
Pingback: essay on ethics in business
Pingback: how much does cialis cost with insurance
Pingback: buy prescription drugs
Pingback: amoxicillin over the counter usa
Pingback: buy lasix water pill
Pingback: buy viagra online usa
Pingback: where can i order zithromax
Pingback: ivermectin 1 cream 45gm
Pingback: where to buy viagra
Pingback: cheap ventolin uk
Pingback: viagra online usa
Pingback: when will viagra be generic
Pingback: generic zithromax over the counter
Pingback: viagra online usa
Pingback: doxycycline drug class
Pingback: prednisolone medicine
Pingback: clomid increase ejaculate
Pingback: dapoxetine vs caber
Pingback: oral thrush diflucan
Pingback: cost of synthroid
Pingback: essays online to buy
Pingback: natural treatments for ed
Pingback: thesis formatting
Pingback: writing a doctoral dissertation
Pingback: zithromax
Pingback: master thesis writing service
Pingback: neurontin 100mg tab
Pingback: write my essay cheap
Pingback: custom essay company
Pingback: buy zithromax no prescription
Pingback: propecia 5
Pingback: do my papers
Pingback: all generic meds from india
Pingback: neurontin and cymbalta
Pingback: metformin davis
Pingback: order paxil online
Pingback: plaquenil drug manufacturer
Pingback: cialis pills online
Pingback: best online pharmacies no prescription
Pingback: viagra without a doctor prescription canada
Pingback: clomid 100 mg tablet
Pingback: amoxicillin no prescription
Pingback: metformin without a script
Pingback: can you order metformin online