public Uri addToGroup(long personId, long groupId) {
this.removeFromGroup(personId, groupId);
ContentValues values = new ContentValues();
values.put(ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID,
personId);
values.put(
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,
groupId);
values
.put(
ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE,
ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE);
return this.ctx.getContentResolver().insert(
ContactsContract.Data.CONTENT_URI, values);
}
2
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor contactsCursor = this.managedQuery(People.CONTENT_URI,
null, null, null, null);
startManagingCursor(contactsCursor);
String[] columnsToMap = new String[] {People.NAME};
int[] mapTo = new int[] {android.R.id.text1};
ListAdapter mAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
contactsCursor, columnsToMap, mapTo);
this.setListAdapter(mAdapter);
3. protected void onListItemClick(ListView l, View v, int position, long id) {
// GET THE ITEM THAT HAD BEEN TAPPED
Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, id);
Cursor c = managedQuery(uri, new String[] {
People.NUMBER
}, null, null, null);
c.moveToFirst();
// CALL THE NUMBER FROM THE PREVIOUS SCREEN\
int phoneNumberIndex = c.getColumnIndex(People.NUMBER);
Uri parsedPhoneNumber = Uri.parse("tel:"+c.getString(phoneNumberIndex));
Intent i = new Intent(Intent.ACTION_CALL,parsedPhoneNumber);
startActivity(i);
super.onListItemClick(l, v, position, id);
}
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
或者
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, IMAGE_PICK);
然后主要是下面的实现
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case REQ_CODE_PICK_IMAGE:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
}
}
}
飞库下载:www.feiku.com 中国移动开发者社区:http://dev.chinamobile.com/cmdn/supesite/