1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
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.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.net.ParseException;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.Toast;
public class Acceuil extends Activity {
ProgressBar seekB;
int progress1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acceuil);
//seekB= (ProgressBar)findViewById(R.id.progressBar1);
ArrayList<BasicNameValuePair> nameValuePair = new ArrayList<BasicNameValuePair>();
String url="http://projects.emerginov.ci/TontineTO/testConexion.php";
//String url="http://10.0.2.2/TontineTO/testConexion.php";
JSONObject JObj=null;
String requete=null;
InputStream is = null;
try{
//commandes httpClient
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePair));
HttpResponse rep = httpclient.execute(httppost);
HttpEntity entity = rep.getEntity();
is = entity.getContent();
}
catch(IOException e){
Toast.makeText(getApplicationContext(),"IOException",Toast.LENGTH_LONG).show();
}
catch(RuntimeException e){
Toast.makeText(getApplicationContext(),"RuntimeException",Toast.LENGTH_LONG).show();
}
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
requete= sb.toString();
//Affichage("BON",requete);
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(),"Erreur Buffer "+e.toString(),Toast.LENGTH_LONG).show();
}
List<String> contenu = new ArrayList<String>();
contenu.add(new String("Choix du Membre"));
int test;
try{
JSONArray jArray = new JSONArray(requete);
JObj = jArray.getJSONObject(0);
test = Integer.parseInt(JObj.getString("etat").toString());
if(test==10){
Toast.makeText(getApplicationContext(),"Connection",Toast.LENGTH_LONG).show();
Intent intent =new Intent(Acceuil.this,MainActivity.class);
startActivity(intent);
}
}catch(JSONException e){
Toast.makeText(getApplicationContext(),"Erreur Json "+e.toString(),Toast.LENGTH_LONG).show();
} catch (ParseException e) {
Toast.makeText(getApplicationContext(),"Erreur JsonP "+e.toString(),Toast.LENGTH_LONG).show();
}
}
} |
Partager