これは、あなたのデータをPHPサーバに投稿してから、そのデータをフェッチしてデータベースに保存する必要があります。
ここでは、サーバー上のデータを送信し、jsonで応答を取得する1つの例を添付します。
HttpPost postMethod = new HttpPost("Your Url");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
// test is a one array list
for(int i=0;i<test.size();i++)
{
nameValuePairs.add(new BasicNameValuePair("sample[]", Integer.toString(test.get(i))));
}
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
DefaultHttpClient hc = new DefaultHttpClient();
HttpResponse response = hc.execute(postMethod);
HttpEntity entity = response.getEntity();
// If the response does not enclose an entity, there is no need
// to worry about connection release
if (entity != null)
{
InputStream inStream = entity.getContent();
result= convertStreamToString(inStream);
jsonObject = new JSONObject(result);
responseHandler.sendEmptyMessage(0);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}.start();
ここで、[]は、サーバー上で送信する配列値を割り当てるフィールドです。サーバー側から、サンプル[]フィールドを取得する必要があります。
public static 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 + "\n");
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return sb.toString();
}私が言おうとしたまさに
。私は、Android OSに含まれているJSONまたはXMLのサポートがかなり良いことを知っています。どちらもあなたのためにうまく動作し、コミュニケーションを可能にします。 ApplicationManifest.xmlのネットワーク操作にアクセスする権限を取得する必要があり、デフォルトのhttpオブジェクト経由でJSONまたはXMLを送信する必要があることに留意してください。 –