私の PHP サービスは、Android フォンから連絡先を受け取る必要があります。このデータをサーバー データベースに挿入するにはどうすればよいですか?
データを配列としてリモート データベースに送信しているときにエラーが発生します。私は何を間違えたのですか?
public class PhoneBookActivity extends Activity {
ListView listViewPhoneBook;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.phone_book);
listViewPhoneBook = (ListView) findViewById(R.id.listPhoneBook);
Cursor cursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[] {Phone._ID, Phone.DISPLAY_NAME, Phone.NUMBER},
null, null, null);
startManagingCursor(cursor);
// Cursor phones = getContentResolver().query(
// ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
// null,
// ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
// null, null);
String[] arrayColumns = new String[]{ Phone.DISPLAY_NAME, Phone.NUMBER, Phone._ID };
int[] arrayViewID = new int[]{ R.id.name , R.id.number, R.id.id };
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
this, R.layout.each_contact, cursor, arrayColumns, arrayViewID);
listViewPhoneBook.setAdapter(adapter);
JSONArray mJSONArray = new JSONArray(Arrays.asList(arrayColumns));
send(mJSONArray);
}
private void send(JSONArray mJSONArray) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.example.org/save_contacts.php?");
httppost.setEntity(new UrlEncodedFormEntity(mJSONArray));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
result = co(is);
}
...