本文整理汇总了Java中android.content.ContentResolver.insert方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResolver.insert方法的具体用法?Java ContentResolver.insert怎么用?Java ContentResolver.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentResolver
的用法示例。
在下文中一共展示了ContentResolver.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveStackBlocking
import android.content.ContentResolver; //导入方法依赖的package包/类
private void saveStackBlocking() {
final ContentResolver resolver = getContentResolver();
final ContentValues values = new ContentValues();
final byte[] rawStack = DurableUtils.writeToArrayOrNull(mState.stack);
if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) {
// Remember stack for last create
values.clear();
values.put(RecentColumns.KEY, mState.stack.buildKey());
values.put(RecentColumns.STACK, rawStack);
resolver.insert(RecentsProvider.buildRecent(), values);
}
// Remember location for next app launch
final String packageName = getCallingPackageMaybeExtra();
values.clear();
values.put(ResumeColumns.STACK, rawStack);
values.put(ResumeColumns.EXTERNAL, 0);
resolver.insert(RecentsProvider.buildResume(packageName), values);
}
示例2: addContactToGroup
import android.content.ContentResolver; //导入方法依赖的package包/类
private static void addContactToGroup(ContentResolver mResolver, int contactId, int groupId)
{
// judge whether the contact has been in the group
boolean b1 = ifExistContactInGroup(mResolver, contactId, groupId);
if (b1)
{
// the contact has been in the group
return;
}
else
{
ContentValues values = new ContentValues();
values.put(ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID, contactId);
values.put(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID, groupId);
values.put(ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE,
ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE);
mResolver.insert(ContactsContract.Data.CONTENT_URI, values);
}
}
示例3: updateVideo
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* 将视频插入图库
*
* @param videoPath 视频路径地址
*/
public static boolean updateVideo(Context context, String videoPath, long videoDuration /*毫秒*/) {
File file = new File(videoPath);
if (!file.exists()) {
return false;
}
//获取ContentResolve对象,来操作插入视频
ContentResolver localContentResolver = context.getContentResolver();
//ContentValues:用于储存一些基本类型的键值对
ContentValues localContentValues = getVideoContentValues(context, file, System.currentTimeMillis(), videoDuration);
//insert语句负责插入一条新的纪录,如果插入成功则会返回这条记录的id,如果插入失败会返回-1。
Uri localUri = localContentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, localContentValues);
L.e("call: updateVideo([context, videoPath])-> " + localUri);
return localUri != null;
}
示例4: checkWriteContacts
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* write and delete contacts info, {@link Manifest.permission#WRITE_CONTACTS}
* and we should get read contacts permission first.
*
* @param activity
* @return true if success
* @throws Exception
*/
private static boolean checkWriteContacts(Context activity) throws Exception {
if (checkReadContacts(activity)) {
// write some info
ContentValues values = new ContentValues();
ContentResolver contentResolver = activity.getContentResolver();
Uri rawContactUri = contentResolver.insert(ContactsContract.RawContacts
.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);
values.put(ContactsContract.Contacts.Data.MIMETYPE, ContactsContract.CommonDataKinds
.StructuredName.CONTENT_ITEM_TYPE);
values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId);
values.put(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, TAG);
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, TAG_NUMBER);
contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);
// delete info
Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
ContentResolver resolver = activity.getContentResolver();
Cursor cursor = resolver.query(uri, new String[]{ContactsContract.Contacts.Data._ID},
"display_name=?", new String[]{TAG}, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int id = cursor.getInt(0);
resolver.delete(uri, "display_name=?", new String[]{TAG});
uri = Uri.parse("content://com.android.contacts/data");
resolver.delete(uri, "raw_contact_id=?", new String[]{id + ""});
}
cursor.close();
}
return true;
} else {
return false;
}
}
示例5: inserModuleInfo
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* 插入module信息操作
*
* @param resolver
*/
public static void inserModuleInfo(ContentResolver resolver, ModuleEntity entity)
{
Uri mModuleUrl = ModuleTable.CONTENT_URI;
ContentValues Moduelvalues = new ContentValues();
String openId = GlobalState.getInstance().getOpenId();
Moduelvalues.put(ModuleTable.OPENID, openId);
Moduelvalues.put(ModuleTable.FUNCODE, entity.getFuncode());
Moduelvalues.put(ModuleTable.FUNNAME, entity.getFunname());
Moduelvalues.put(ModuleTable.FUNICON, entity.getFunicon());
Moduelvalues.put(ModuleTable.FUNICON_L, entity.getFunicon_l());
Moduelvalues.put(ModuleTable.FUNCLASSPATH, entity.getFunclasspath());
Moduelvalues.put(ModuleTable.ISABLE, entity.getIsAble());
Moduelvalues.put(ModuleTable.ISADD, entity.getIsAdd());
Moduelvalues.put(ModuleTable.SORT_IN_ADDLIST, entity.getSort_in_addlist());
Moduelvalues.put(ModuleTable.SORT_IN_TEAM, entity.getSort_in_team());
Moduelvalues.put(ModuleTable.TYPE, entity.getType());
Moduelvalues.put(ModuleTable.VALUE, entity.getValue());
Moduelvalues.put(ModuleTable.COUNT_ABLE, entity.getCount_able());
Moduelvalues.put(ModuleTable.COUNT_ICON_1, entity.getCount_icon_1());
Moduelvalues.put(ModuleTable.COUNT_ICON_2, entity.getCount_icon_2());
Moduelvalues.put(ModuleTable.COUNT_TYPE, entity.getCount_type());
Moduelvalues.put(ModuleTable.PCODE, entity.getpCode());
Moduelvalues.put(ModuleTable.PNAME, entity.getpName());
Moduelvalues.put(ModuleTable.ATTAHCURL, entity.getAttachURL());
Moduelvalues.put(ModuleTable.ICONURL, entity.getIconURL());
Moduelvalues.put(ModuleTable.VERSION, entity.getVersion());
resolver.insert(mModuleUrl, Moduelvalues);
}
示例6: addNewPlaylist
import android.content.ContentResolver; //导入方法依赖的package包/类
public static Uri addNewPlaylist(ContentResolver Cr, String str){
Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Playlists.NAME, str);
values.put(MediaStore.Audio.Playlists.DATE_ADDED,
System.currentTimeMillis());
values.put(MediaStore.Audio.Playlists.DATE_MODIFIED,
System.currentTimeMillis());
Uri Got = Cr.insert(uri, values);
return Got;
}
示例7: createImage
import android.content.ContentResolver; //导入方法依赖的package包/类
private Uri createImage() throws SecurityException {
ContentResolver contentResolver = getContentResolver();
ContentValues cv = new ContentValues();
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
cv.put(MediaStore.Images.Media.TITLE, timeStamp);
return contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cv);
}
示例8: insert
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* This doesn't do anything other than call "insert" on the content
* resolver, but I thought I'd put it here in the interests of having
* each of the CRUD methods available in the helper class.
*/
public static Uri insert(Context context,
ContentValues values) {
ContentResolver resolver = context.getContentResolver();
Uri uri = RepoProvider.getContentUri();
return resolver.insert(uri, values);
}
示例9: checkWriteCallLog
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* write or delete call log, {@link android.Manifest.permission#WRITE_CALL_LOG}
*
* @param activity
* @return true if success
*/
private static boolean checkWriteCallLog(Activity activity) throws Exception {
ContentResolver contentResolver = activity.getContentResolver();
ContentValues content = new ContentValues();
content.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
content.put(CallLog.Calls.NUMBER, TAG_NUMBER);
content.put(CallLog.Calls.DATE, 20140808);
content.put(CallLog.Calls.NEW, "0");
contentResolver.insert(Uri.parse("content://call_log/calls"), content);
contentResolver.delete(Uri.parse("content://call_log/calls"), "number = ?", new
String[]{TAG_NUMBER});
return true;
}
示例10: restoreSipProfile
import android.content.ContentResolver; //导入方法依赖的package包/类
private static boolean restoreSipProfile(JSONObject jsonObj, ContentResolver cr) {
// Restore accounts
Columns cols;
ContentValues cv;
cols = getSipProfileColumns(false);
cv = cols.jsonToContentValues(jsonObj);
long profileId = cv.getAsLong(SipProfile.FIELD_ID);
if(profileId >= 0) {
Uri insertedUri = cr.insert(SipProfile.ACCOUNT_URI, cv);
profileId = ContentUris.parseId(insertedUri);
}
// TODO : else restore call handler in private db
// Restore filters
cols = new Columns(Filter.FULL_PROJ, Filter.FULL_PROJ_TYPES);
try {
JSONArray filtersObj = jsonObj.getJSONArray(FILTER_KEY);
Log.d(THIS_FILE, "We have filters for " + profileId + " > " + filtersObj.length());
for (int i = 0; i < filtersObj.length(); i++) {
JSONObject filterObj = filtersObj.getJSONObject(i);
// Log.d(THIS_FILE, "restoring "+filterObj.toString(4));
cv = cols.jsonToContentValues(filterObj);
cv.put(Filter.FIELD_ACCOUNT, profileId);
cr.insert(SipManager.FILTER_URI, cv);
}
} catch (JSONException e) {
Log.e(THIS_FILE, "Error while restoring filters", e);
}
return false;
}
示例11: on_pager
import android.content.ContentResolver; //导入方法依赖的package包/类
@Override
public void on_pager(int callId, pj_str_t from, pj_str_t to, pj_str_t contact,
pj_str_t mime_type, pj_str_t body) {
lockCpu();
long date = System.currentTimeMillis();
String fromStr = PjSipService.pjStrToString(from);
String canonicFromStr = SipUri.getCanonicalSipContact(fromStr);
String contactStr = PjSipService.pjStrToString(contact);
String toStr = PjSipService.pjStrToString(to);
String bodyStr = PjSipService.pjStrToString(body);
String mimeStr = PjSipService.pjStrToString(mime_type);
// Sanitize from sip uri
int slashIndex = fromStr.indexOf("/");
if (slashIndex != -1){
fromStr = fromStr.substring(0, slashIndex);
}
SipMessage msg = new SipMessage(canonicFromStr, toStr, contactStr, bodyStr, mimeStr,
date, SipMessage.MESSAGE_TYPE_INBOX, fromStr);
// Insert the message to the DB
ContentResolver cr = pjService.service.getContentResolver();
cr.insert(SipMessage.MESSAGE_URI, msg.getContentValues());
// Broadcast the message
Intent intent = new Intent(SipManager.ACTION_SIP_MESSAGE_RECEIVED);
// TODO : could be parcelable !
intent.putExtra(SipMessage.FIELD_FROM, msg.getFrom());
intent.putExtra(SipMessage.FIELD_BODY, msg.getBody());
pjService.service.sendBroadcast(intent, SipManager.PERMISSION_USE_SIP);
// Notify android os of the new message
notificationManager.showNotificationForMessage(msg);
unlockCpu();
}
示例12: addBarrageToUri
import android.content.ContentResolver; //导入方法依赖的package包/类
public static Uri addBarrageToUri(ContentResolver cr, Uri uri, String address, String body, Long date, int count, long barrageId) {
ContentValues values = new ContentValues(5);
values.put(TextBasedBarrageColumns.ADDRESS, address);
values.put(TextBasedBarrageColumns.BODY, body);
if (date != null)
values.put(TextBasedBarrageColumns.DATE, date);
values.put(TextBasedBarrageColumns.COUNT, count);
if (barrageId != -1L)
values.put(TextBasedBarrageColumns.BARRAGE_ID, barrageId);
return cr.insert(uri, values);
}
示例13: AddContact
import android.content.ContentResolver; //导入方法依赖的package包/类
public static void AddContact(ContentResolver mResolver, String name, String number, String groupName)
{
Log.i("hoperun", "name= " + name + ";number=" + number);
if (!queryFromContact(mResolver, name, number))
{
ContentValues values = new ContentValues();
// 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
Uri rawContactUri = mResolver.insert(RawContacts.CONTENT_URI, values);
if (rawContactUri != null)
{
long rawContactId = ContentUris.parseId(rawContactUri);
// 往data表插入姓名数据
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);// 内容类型
values.put(StructuredName.GIVEN_NAME, name);
mResolver.insert(ContactsContract.Data.CONTENT_URI, values);
// 往data表插入电话数据
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, number);
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
mResolver.insert(ContactsContract.Data.CONTENT_URI, values);
}
else
{
Log.i("hoperun", "name= " + name + ";number=" + number);
}
}
else
{
Log.i("hoperun", "repeat name= " + name + ";number=" + number);
}
}
示例14: addItemToDatabase
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Add an item to the database in a specified container. Sets the container, screen, cellX and
* cellY fields of the item. Also assigns an ID to the item.
*/
public static void addItemToDatabase(Context context, final ItemInfo item, final long container,
final long screenId, final int cellX, final int cellY) {
item.container = container;
item.cellX = cellX;
item.cellY = cellY;
// We store hotseat items in canonical form which is this orientation invariant position
// in the hotseat
if (context instanceof Launcher && screenId < 0 &&
container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
item.screenId = Launcher.getLauncher(context).getHotseat()
.getOrderInHotseat(cellX, cellY);
} else {
item.screenId = screenId;
}
final ContentValues values = new ContentValues();
final ContentResolver cr = context.getContentResolver();
item.onAddToDatabase(context, values);
item.id = LauncherSettings.Settings.call(cr, LauncherSettings.Settings.METHOD_NEW_ITEM_ID)
.getLong(LauncherSettings.Settings.EXTRA_VALUE);
values.put(LauncherSettings.Favorites._ID, item.id);
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
Runnable r = new Runnable() {
public void run() {
cr.insert(LauncherSettings.Favorites.CONTENT_URI, values);
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
checkItemInfoLocked(item.id, item, stackTrace);
sBgItemsIdMap.put(item.id, item);
switch (item.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
sBgFolders.put(item.id, (FolderInfo) item);
// Fall through
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP ||
item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
sBgWorkspaceItems.add(item);
} else {
if (!sBgFolders.containsKey(item.container)) {
// Adding an item to a folder that doesn't exist.
String msg = "adding item: " + item + " to a folder that " +
" doesn't exist";
Log.e(TAG, msg);
}
}
if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
incrementPinnedShortcutCount(
ShortcutKey.fromShortcutInfo((ShortcutInfo) item),
true /* shouldPin */);
}
break;
case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
sBgAppWidgets.add((LauncherAppWidgetInfo) item);
break;
}
}
}
};
runOnWorkerThread(r);
}
示例15: testInsert
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Tests inserting a single row of data via a ContentResolver
*/
@Test
public void testInsert() {
/* Create values to insert */
ContentValues testTaskValues = new ContentValues();
testTaskValues.put(TaskContract.TaskEntry.COLUMN_DESCRIPTION, "Test description");
testTaskValues.put(TaskContract.TaskEntry.COLUMN_PRIORITY, 1);
/* TestContentObserver allows us to test if notifyChange was called appropriately */
TestUtilities.TestContentObserver taskObserver = TestUtilities.getTestContentObserver();
ContentResolver contentResolver = mContext.getContentResolver();
/* Register a content observer to be notified of changes to data at a given URI (tasks) */
contentResolver.registerContentObserver(
/* URI that we would like to observe changes to */
TaskContract.TaskEntry.CONTENT_URI,
/* Whether or not to notify us if descendants of this URI change */
true,
/* The observer to register (that will receive notifyChange callbacks) */
taskObserver);
Uri uri = contentResolver.insert(TaskContract.TaskEntry.CONTENT_URI, testTaskValues);
Uri expectedUri = ContentUris.withAppendedId(TaskContract.TaskEntry.CONTENT_URI, 1);
String insertProviderFailed = "Unable to insert item through Provider";
assertEquals(insertProviderFailed, uri, expectedUri);
/*
* If this fails, it's likely you didn't call notifyChange in your insert method from
* your ContentProvider.
*/
taskObserver.waitForNotificationOrFail();
/*
* waitForNotificationOrFail is synchronous, so after that call, we are done observing
* changes to content and should therefore unregister this observer.
*/
contentResolver.unregisterContentObserver(taskObserver);
}