How to Convert ArrayList<> to string …
Details:
step1: send e-mail address to php mySql database
step2: if email address match database content, echoed success
step3: retrieved the php echoed value (“success”)
step4: assign the the response to a string phpEchoedVal
step5: compare phpEchoedVal with “success”
step6: write email to sd card
is this one ok
//url = email address
ArrayList nameValuePair = new ArrayList(1);
nameValuePair.add(new BasicNameValuePair("url", url));
try {
//open an httpclient connection
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(strLink);
httppost.setEntity(new UrlEncodedFormEntity(data));
//response retrieve "success" echoed from server
ResponseHandler<String> handleResponse = new BasicResponseHandler();
//converts server response to string.
String phpEchoVal = httpclient.execute(httppost, handleResponse);
txtInfo.setText(phpEchoVal);
String containEmail = txtInfo.getText().toString();
//compare response from server with local string
// if successful write email to sd card
if ((containEmail.equals("success"))){
//create a new text file
File myFile = new File("/sdcard/moLarouteReg.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append(containEmail);
//close writer
myOutWriter.close();
fOut.close();
//Open menu
Intent openMenu = new Intent("com.molaroute.mu.Menu");
startActivity(openMenu);
finish();
Log.d("test","fileWritten: "+myOutWriter);
}else {
...
}
}
For your first question; how to match strings in an array list(containting name value pair objects) to other strings:
You can also check if a text contains another text instead of checking for equality.
Ofcourse you can do alot more, but this should give you the basic idea..
For your second question:
HttpClient.execute() returns an HttpResponse.
From HttpResponse you can call getEntity which returns an HttpEntity
From HttpEntity you can call getContent which returns an InputStream.
This InputStream you can convert to string. Example conversion code snippets are widely on the net.
so the code:
Note that IOUtility is self written class in this case.
I think there are other ways to convert a HttpResponse to a string, but this is how I do it.
_inStream is an InputStream, entity is an HttpEntity, the rest should be self explanatory.