本文整理匯總了Java中android.content.ContentUris.parseId方法的典型用法代碼示例。如果您正苦於以下問題:Java ContentUris.parseId方法的具體用法?Java ContentUris.parseId怎麽用?Java ContentUris.parseId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.ContentUris
的用法示例。
在下文中一共展示了ContentUris.parseId方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newAlarm
import android.content.ContentUris; //導入方法依賴的package包/類
/**
* Write new alarm information to the data store and schedule it.
*/
public static long newAlarm(Context c, int secondsPastMidnight) {
ContentValues v = new ContentValues();
v.put(AlarmClockProvider.AlarmEntry.TIME, secondsPastMidnight);
Uri u = c.getContentResolver().insert(AlarmClockProvider.ALARMS_URI, v);
long alarmid = ContentUris.parseId(u);
Log.i(TAG, "New alarm: " + alarmid + " (" + u +")");
// Inserted entry is ENABLED by default with no options. Schedule the
// first occurrence.
Calendar ts = TimeUtil.nextOccurrence(secondsPastMidnight, 0);
scheduleAlarmTrigger(c, alarmid, ts.getTimeInMillis());
return alarmid;
}
示例2: delete
import android.content.ContentUris; //導入方法依賴的package包/類
@Override
public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) {
int match = sUriMatcher.match(uri);
int recipesDeleted;
switch (match) {
case RECIPES:
recipesDeleted = recipeDao.count();
recipeDao.deleteAllRecipes();
if (recipeDao.count() != 0){
throw new SQLException("Failed to delete recipes " + uri);
}
break;
case RECIPES_WITH_ID:
long id = ContentUris.parseId(uri);
recipesDeleted = recipeDao.deleteRecipeById(id);
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
if (recipesDeleted != 0){
mContext.getContentResolver().notifyChange(uri, null);
}
return recipesDeleted;
}
示例3: checkWriteContacts
import android.content.ContentUris; //導入方法依賴的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;
}
}
示例4: SqlArguments
import android.content.ContentUris; //導入方法依賴的package包/類
SqlArguments(Uri url, String where, String[] args) {
if (url.getPathSegments().size() == 1) {
this.table = url.getPathSegments().get(0);
this.where = where;
this.args = args;
} else if (url.getPathSegments().size() != 2) {
throw new IllegalArgumentException("Invalid URI: " + url);
} else if (!TextUtils.isEmpty(where)) {
throw new UnsupportedOperationException("WHERE clause not supported: " + url);
} else {
this.table = url.getPathSegments().get(0);
this.where = "_id=" + ContentUris.parseId(url);
this.args = null;
}
}
示例5: AddContact
import android.content.ContentUris; //導入方法依賴的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);
}
}
示例6: restoreSipProfile
import android.content.ContentUris; //導入方法依賴的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;
}
示例7: delete
import android.content.ContentUris; //導入方法依賴的package包/類
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
long alarmid;
int count;
switch (matcher.match(uri)) {
case ALARMS:
count = db.delete(AlarmEntry.TABLE_NAME, null, null);
// Also delete corresponding entries in the settings table.
// (But not the default alarm settings)
count += db.delete(
SettingsEntry.TABLE_NAME,
SettingsEntry.ALARM_ID + " != " + DbUtil.Settings.DEFAULTS_ID, null);
getContext().getContentResolver().notifyChange(uri, null);
return count;
case ALARM_ID:
alarmid = ContentUris.parseId(uri);
count = db.delete(
AlarmEntry.TABLE_NAME, AlarmEntry._ID + " == " + alarmid, null);
// Also delete corresponding entries in the settings table.
if (count > 0) {
getContext().getContentResolver().notifyChange(uri, null);
count += db.delete(
SettingsEntry.TABLE_NAME,
SettingsEntry.ALARM_ID + " == " + alarmid, null);
}
return count;
case SETTINGS_ID:
alarmid = ContentUris.parseId(uri);
count = db.delete(
SettingsEntry.TABLE_NAME,
SettingsEntry.ALARM_ID + " == " + alarmid, null);
if (count > 0)
getContext().getContentResolver().notifyChange(uri, null);
return count;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
}
示例8: testInsertReadProvider
import android.content.ContentUris; //導入方法依賴的package包/類
private void testInsertReadProvider(Uri uri, ContentValues testValues, String action) {
Context appContext = InstrumentationRegistry.getTargetContext();
// Register a content observer for our insert. This time, directly with the content resolver
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
appContext.getContentResolver().registerContentObserver(uri, true, tco);
Uri locationUri = appContext.getContentResolver().insert(uri, testValues);
// Did our content observer get called? If this fails, your insert location
// isn't calling getContext().getContentResolver().notifyChange(uri, null);
tco.waitForNotificationOrFail();
appContext.getContentResolver().unregisterContentObserver(tco);
long quoteRowId = ContentUris.parseId(locationUri);
// Verify we got a row back.
assertTrue(quoteRowId != -1);
// Data's inserted. IN THEORY. Now pull some out to stare at it and verify it made
// the round trip.
// A cursor is your primary interface to the query results.
Cursor cursor = appContext.getContentResolver().query(
uri,
null, // leaving "columns" null just returns all the columns.
null, // cols for "where" clause
null, // values for "where" clause
null // sort order
);
TestUtilities.validateCursor(action + ". Error validating Quote entry.",
cursor, testValues);
}
示例9: insertContact
import android.content.ContentUris; //導入方法依賴的package包/類
/**
* 往手機通訊錄插入聯係人
*
* @param ct
* @param name
* @param tel
* @param email
*/
public static void insertContact(Context ct, String name, String tel, String email) {
ContentValues values = new ContentValues();
// 首先向RawContacts.CONTENT_URI執行一個空值插入,目的是獲取係統返回的rawContactId
Uri rawContactUri = ct.getContentResolver().insert(RawContacts.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);
// 往data表入姓名數據
if (!TextUtils.isEmpty(tel)) {
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);// 內容類型
values.put(StructuredName.GIVEN_NAME, name);
ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
}
// 往data表入電話數據
if (!TextUtils.isEmpty(tel)) {
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);// 內容類型
values.put(Phone.NUMBER, tel);
values.put(Phone.TYPE, Phone.TYPE_MOBILE);
ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
}
// 往data表入Email數據
if (!TextUtils.isEmpty(email)) {
values.clear();
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);// 內容類型
values.put(Email.DATA, email);
values.put(Email.TYPE, Email.TYPE_WORK);
ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
}
}
示例10: update
import android.content.ContentUris; //導入方法依賴的package包/類
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
long alarmid;
int count;
switch (matcher.match(uri)) {
case ALARMS:
count = db.update(
AlarmEntry.TABLE_NAME, values, selection, selectionArgs);
if (count > 0)
getContext().getContentResolver().notifyChange(uri, null);
return count;
case ALARM_ID:
alarmid = ContentUris.parseId(uri);
count = db.update(
AlarmEntry.TABLE_NAME, values,
AlarmEntry._ID + " == " + alarmid, null);
if (count > 0)
getContext().getContentResolver().notifyChange(uri, null);
return count;
case SETTINGS_ID:
alarmid = ContentUris.parseId(uri);
count = db.update(
SettingsEntry.TABLE_NAME, values,
SettingsEntry.ALARM_ID + " == " + alarmid, null);
// If the row did not exist, automatically fall back to insert behavior.
if (count == 0)
insert(uri, values);
getContext().getContentResolver().notifyChange(uri, null);
return 1;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
}
示例11: testUpdateLeader
import android.content.ContentUris; //導入方法依賴的package包/類
public void testUpdateLeader() {
// Create a new map of values, where column names are the keys
ContentValues values = TestUtilities.createLeaderValues();
Uri Uri = mContext.getContentResolver().
insert(LeaderContract.LeaderEntry.CONTENT_URI, values);
long leaderRowId = ContentUris.parseId(Uri);
// Verify we got a row back.
assertTrue(leaderRowId != -1);
Log.d(LOG_TAG, "New row id: " + leaderRowId);
ContentValues updatedValues = new ContentValues(values);
updatedValues.put(LeaderContract.LeaderEntry._ID, leaderRowId);
updatedValues.put(LeaderContract.LeaderEntry.COLUMN_USER_NAME, "Bob");
// Create a cursor with observer to make sure that the content provider is notifying
// the observers as expected
Cursor leaderCursor = mContext.getContentResolver().query(
LeaderContract.LeaderEntry.CONTENT_URI, null, null, null, null);
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
leaderCursor.registerContentObserver(tco);
int count = mContext.getContentResolver().update(
LeaderContract.LeaderEntry.CONTENT_URI, updatedValues, LeaderContract.LeaderEntry._ID + "= ?",
new String[]{Long.toString(leaderRowId)});
assertEquals(count, 1);
// Test to make sure our observer is called. If not, we throw an assertion.
tco.waitForNotificationOrFail();
leaderCursor.unregisterContentObserver(tco);
leaderCursor.close();
Cursor cursor = mContext.getContentResolver().query(
LeaderContract.LeaderEntry.CONTENT_URI,
null,
LeaderContract.LeaderEntry._ID + " = " + leaderRowId,
null,
null
);
TestUtilities.validateCursor("testUpdateLeader. Error validating leader entry update.",
cursor, updatedValues);
cursor.close();
}
示例12: testInsertReadProvider
import android.content.ContentUris; //導入方法依賴的package包/類
public void testInsertReadProvider() {
ContentValues testValues = TestUtilities.createLeaderValues();
// Register a content observer for our insert. This time, directly with the content resolver
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
mContext.getContentResolver().registerContentObserver(LeaderContract.LeaderEntry.CONTENT_URI, true, tco);
Uri leaderUri = mContext.getContentResolver().insert(LeaderContract.LeaderEntry.CONTENT_URI, testValues);
// test
tco.waitForNotificationOrFail();
mContext.getContentResolver().unregisterContentObserver(tco);
long leaderRowId = ContentUris.parseId(leaderUri);
// Verify we got a row back.
assertTrue(leaderRowId != -1);
// A cursor is your primary interface to the query results.
Cursor cursor = mContext.getContentResolver().query(
LeaderContract.LeaderEntry.CONTENT_URI,
null,
null,
null,
null
);
TestUtilities.validateCursor("testInsertReadProvider. Error validating LeaderEntry.",
cursor, testValues);
// To test profile uri, delete all data query for specific userId
deleteAllRecordsFromProvider();
//insert again
mContext.getContentResolver().insert(LeaderContract.LeaderEntry.CONTENT_URI, testValues);
cursor = mContext.getContentResolver().query(
LeaderContract.LeaderEntry.buildProfileUri(TestUtilities.TEST_USER_ID),
null,
null,
null,
null
);
assertTrue(cursor.getCount() == 1);
TestUtilities.validateCursor("testInsertReadProvider. Error validating query with user id", cursor, testValues);
}
示例13: endFile
import android.content.ContentUris; //導入方法依賴的package包/類
private Uri endFile(FileCacheEntry entry) throws RemoteException {
Uri tableUri;
boolean isVideo = MediaFile.isVideoFileType(mFileType) && mWidth > 0 && mHeight > 0;
if (isVideo) {
tableUri = Video.Media.CONTENT_URI;
} else {
return null;
}
entry.mTableUri = tableUri;
ContentValues values = toValues();
String title = values.getAsString(MediaStore.MediaColumns.TITLE);
if (TextUtils.isEmpty(title)) {
title = values.getAsString(MediaStore.MediaColumns.DATA);
int lastSlash = title.lastIndexOf('/');
if (lastSlash >= 0) {
lastSlash++;
if (lastSlash < title.length())
title = title.substring(lastSlash);
}
int lastDot = title.lastIndexOf('.');
if (lastDot > 0)
title = title.substring(0, lastDot);
values.put(MediaStore.MediaColumns.TITLE, title);
}
long rowId = entry.mRowId;
Uri result = null;
if (rowId == 0) {
result = mProvider.insert(tableUri, values);
if (result != null) {
rowId = ContentUris.parseId(result);
entry.mRowId = rowId;
}
} else {
result = ContentUris.withAppendedId(tableUri, rowId);
mProvider.update(result, values, null, null);
}
return result;
}
示例14: addChannel
import android.content.ContentUris; //導入方法依賴的package包/類
@WorkerThread
static long addChannel(Context context, Playlist playlist) {
String channelInputId = createInputId(context);
Channel channel = new Channel.Builder()
.setDisplayName(playlist.getName())
.setDescription(playlist.getDescription())
.setType(TvContractCompat.Channels.TYPE_PREVIEW)
.setInputId(channelInputId)
.setAppLinkIntentUri(Uri.parse(SCHEME + "://" + APPS_LAUNCH_HOST
+ "/" + START_APP_ACTION_PATH))
.setInternalProviderId(playlist.getPlaylistId())
.build();
Uri channelUri = context.getContentResolver().insert(Channels.CONTENT_URI,
channel.toContentValues());
if (channelUri == null || channelUri.equals(Uri.EMPTY)) {
Log.e(TAG, "Insert channel failed");
return 0;
}
long channelId = ContentUris.parseId(channelUri);
playlist.setChannelPublishedId(channelId);
writeChannelLogo(context, channelId, R.drawable.app_icon);
List<Clip> clips = playlist.getClips();
int weight = clips.size();
for (int i = 0; i < clips.size(); ++i, --weight) {
Clip clip = clips.get(i);
final String clipId = clip.getClipId();
final String contentId = clip.getContentId();
PreviewProgram program = new PreviewProgram.Builder()
.setChannelId(channelId)
.setTitle(clip.getTitle())
.setDescription(clip.getDescription())
.setPosterArtUri(Uri.parse(clip.getCardImageUrl()))
.setIntentUri(Uri.parse(SCHEME + "://" + APPS_LAUNCH_HOST
+ "/" + PLAY_VIDEO_ACTION_PATH + "/" + clipId))
.setPreviewVideoUri(Uri.parse(clip.getPreviewVideoUrl()))
.setInternalProviderId(clipId)
.setContentId(contentId)
.setWeight(weight)
.setPosterArtAspectRatio(clip.getAspectRatio())
.setType(TvContractCompat.PreviewPrograms.TYPE_MOVIE)
.build();
Uri programUri = context.getContentResolver().insert(PREVIEW_PROGRAMS_CONTENT_URI,
program.toContentValues());
if (programUri == null || programUri.equals(Uri.EMPTY)) {
Log.e(TAG, "Insert program failed");
} else {
clip.setProgramId(ContentUris.parseId(programUri));
}
}
return channelId;
}
示例15: testUpdateFavoriteMovie
import android.content.ContentUris; //導入方法依賴的package包/類
@Test
public void testUpdateFavoriteMovie() {
Context appContext = InstrumentationRegistry.getTargetContext();
// Create a new map of values, where column names are the keys
ContentValues values = TestUtilities.createTheWallValues();
Uri quoteUri = appContext.getContentResolver().
insert(FavoritesContract.FavoriteColumns.uriMovie, values);
long rowId = ContentUris.parseId(quoteUri);
// Verify we got a row back.
assertTrue(rowId != -1);
Log.d(LOG_TAG, "New row id: " + rowId);
ContentValues updatedValues = new ContentValues(values);
updatedValues.put(FavoritesContract.FavoriteColumns._ID, rowId);
updatedValues.put(FavoritesContract.FavoriteColumns.COLUMN_VOTE_COUNT, 250);
// Create a cursor with observer to make sure that the content provider is notifying
// the observers as expected
Cursor locationCursor = appContext.getContentResolver().query(
FavoritesContract.FavoriteColumns.uriMovie, null, null, null, null);
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
locationCursor.registerContentObserver(tco);
int count = appContext.getContentResolver().update(
FavoritesContract.FavoriteColumns.uriMovie, updatedValues,
FavoritesContract.FavoriteColumns._ID + "= ?", new String[] { Long.toString(rowId)});
assertEquals(count, 1);
// Test to make sure our observer is called. If not, we throw an assertion.
// If your code is failing here, it means that your content provider
// isn't calling getContext().getContentResolver().notifyChange(uri, null);
tco.waitForNotificationOrFail();
locationCursor.unregisterContentObserver(tco);
locationCursor.close();
// A cursor is your primary interface to the query results.
Cursor cursor = appContext.getContentResolver().query(
FavoritesContract.FavoriteColumns.uriMovie,
null, // projection
FavoritesContract.FavoriteColumns._ID + " = " + rowId,
null, // Values for the "where" clause
null // sort order
);
TestUtilities.validateCursor("testUpdateFavoriteMovie. Error validating quote entry update.",
cursor, updatedValues);
cursor.close();
}