私はAndroidが初めてで、解決方法がわからない問題でブロックされています。サーバー上のxmlファイルを変更するために、アプリからこのフォームのメッセージをサーバーに送信しようとしています:
https://myserver/index.php?x0=param1&y0=param2&z0=param3
param1、param2、および param3 の固定値で機能させることができました。つまり、以下のコードを使用して、サーバー上の xml ファイルの値を 1、2、および 3 に変更します。
private OnClickListener InitialPosListener = new OnClickListener() {
@Override
public void onClick(View v) {
String x00 = InitialPosX.getText().toString(); String y00 = InitialPosY.getText().toString(); String z00 = InitialPosZ.getText().toString();
float x0 = Float.valueOf(x00); float y0 = Float.valueOf(y00); float z0 = Float.valueOf(z00);
new RequestTask().execute(https://myserver/index.php?x0=1&y0=2&z0=3);
}
};
class RequestTask extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... uri) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
//TODO Handle problems..
} catch (IOException e) {
//TODO Handle problems..
}
return responseString;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
//Do anything with response..
}
}
しかし、私の問題は、固定値ではなく、ユーザーが入力し、「InitialPosListener」で読み取られる値(変数)を送信したいことです:x00、y00、およびz00 ...
これを行う方法はありますか?どうもありがとう