list.get(position).get(NAME).toString(), list.get(position).get(NUMBER).toString());
selectlist.add(person);
}
});
contactsOkBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = getIntent();
Pool.put("contacts", selectlist);
ContactsActivity.this.setResult(RESULT_OK, intent);
ContactsActivity.this.finish();
}
});
}
private List<Map<String, Object>> getContacts(){
List<Map<String, Object>> list = null;
Cursor cur = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
while(cur.moveToNext()){
if(list == null){
list = new ArrayList<Map<String,Object>>();
}
Map<String, Object> map = new HashMap<String, Object>();
long id = cur.getLong(cur.getColumnIndex("_id"));
Cursor pcur = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +"="+Long.toString(id), null, null);
String phoneNumbers = "";
while(pcur.moveToNext()){
phoneNumbers += pcur.getString(pcur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
pcur.close();
String name = cur.getString(cur.getColumnIndex("display_name"));
map.put(NAME, name);
map.put(NUMBER, phoneNumbers);
list.add(map);
}
cur.close();
return list;
}
}
AddActivity
package com.huawei.phonerecorder.activity;
import com.huawei.phonerecorder.R;
public class AddActivity extends Activity {
private static final String TAG = "InfoActivity";
private Button okBtn;
private EditText nameText;
private EditText phoneText;
private Bundle bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.info);
init();
}
private void init(){
okBtn = (Button)findViewById(R.id.ok);
nameText = (EditText)findViewById(R.id.name);
phoneText = (EditText)findViewById(R.id.phone);
Intent i = getIntent();
Bundle b = i.getExtras();
if(b != null){
Log.d(TAG, "ID ==> " + b.getString("id"));
if(b.getString("id")!=null){
nameText.setText(b.getString("name"));
phoneText.setText(b.getString("phone"));
Log.d(TAG, "Name ==> " + b.getString("name"));
}
}
okBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = getIntent();
Bundle bundle = new Bundle();
bundle.putBoolean("start", true);
bundle.putString("name", nameText.getText().toString());
bundle.putString("phone", phoneText.getText().toString());
intent.putExtras(bundle);
AddActivity.this.setResult(RESULT_OK, intent);
AddActivity.this.finish();
}
});
}
}
DataOpenHelper
package com.huawei.phonerecorder.db;
import java.util.List;
public class DataOpenHelper extends SQLiteOpenHelper {
private static final String TAG = "DataOpenHelper";
private static final String TABLE_NAME = "PERSON";
private static final int VERSION = 1;
private static final String CREATE_TABLE = "CREATE TABLE PERSON(ID INTEGER PRIMARY KEY AUTOINCREMENT," +