我有代码从android中的联系人发送数据电话。正如我们所知,android 中电话联系人中的许多数据。我有代码可以从电话联系人中获取数据并显示为这样的列表视图
Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
int row = cursor.getCount();
friend_item = new MenuItem [row];
int i=0;
while(cursor.moveToNext()){
nama = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
phone = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
friend_item[i] = new MenuItem(nama,phone);
i++;
}
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("phone", mPhoneNumber));
params.add(new BasicNameValuePair("friend", phone));
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(Constants.url_phone_contact, "POST", params);
// Check your log cat for JSON reponse
Log.d("All Friend: ", json.toString());
try {
friend = json.getJSONArray("friend");
friend_item = new MenuItem[friend.length()];
// looping through All Products
for (int a = 0; a < friend.length(); a++) {
JSONObject c = friend.getJSONObject(i);
//Storing each json item in variable
String phone_friend= c.getString(TAG_PHONE);
friend_item[i] = new MenuItem(nama, phone_friend);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put("nama", nama);
map.put("phone", phone_friend);
// adding HashList to ArrayList
friendList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
在params.add(new BasicNameValuePair("friend", phone));
朋友是数据数组,来自 [phone_contact] 的数组。那么我如何将数据数组和字符串“mPhoneNumber”发送到android中的服务器?谢谢