android平台中调用系统界面
2012-12-25 19:08:20 来源:WEB开发网i.setComponent(cn);
i.setAction("android.intent.action.MAIN");
startActivityForResult(i, RESULT_OK);
20 添加到短信收件箱
ContentValues cv = new ContentValues();
cv.put("type", "1");
cv.put("address","短信地址");
cv.put("body", "短信内容");
getContentResolver().insert(Uri.parse("content://sms/inbox"), cv);
21 从sim卡或者联系人中查询
Cursor cursor;
Uri uri;
if (type == 1) {
Intent intent = new Intent();
intent.setData(Uri.parse("content://icc/adn"));
uri = intent.getData();
} else
uri = People.CONTENT_URI;
cursor = activity.getContentResolver().query(uri, null, null, null, null);
while (cursor.moveToNext()) {
int peopleId = cursor.getColumnIndex(People._ID);
int nameId = cursor.getColumnIndex(People.NAME);
int phoneId = cursor.getColumnIndex(People.NUMBER);}
查看某个联系人,当然这里是ACTION_VIEW,
如果为选择并返回action改为ACTION_PICK,当然处理intent时返回需要用到 startActivityforResult
Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, ID);
//最后的ID参数为联系人Provider中的数据库BaseID,即哪一行
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW);
intent.setData(personUri); startActivity(intent);
22 删除
uri = ContentUris.withAppendedId(People.CONTENT_URI, 联系人id);
int count = activity.getContentResolver().delete(uri, null, null);
23 添加到联系人:
ContentValues cv = new ContentValues();
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder =
ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
builder.withValues(cv);
operationList.add(builder.build());
builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
builder.withValueBackReference(StructuredName.RAW_CONTACT_ID, 0);
builder.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
builder.withValue(StructuredName.DISPLAY_NAME, "自定义联系人名");
operationList.add(builder.build());
builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
builder.withValueBackReference(Phone.RAW_CONTACT_ID, 0);
builder.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
builder.withValue(Phone.NUMBER, "联系人的phonenumber");
builder.withValue(Data.IS_PRIMARY, 1);
operationList.add(builder.build());
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, operationList);
} catch (RemoteException e) {
e.printStackTrace();
} catch (OperationApplicationException e) {
e.printStackTrace();
}
23 选择一个图片
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
更多精彩
赞助商链接