我的 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);
}
...