本文整理匯總了Java中android.content.ContentUris.withAppendedId方法的典型用法代碼示例。如果您正苦於以下問題:Java ContentUris.withAppendedId方法的具體用法?Java ContentUris.withAppendedId怎麽用?Java ContentUris.withAppendedId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.ContentUris
的用法示例。
在下文中一共展示了ContentUris.withAppendedId方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: prepareEditContactIntentWithSipAddress
import android.content.ContentUris; //導入方法依賴的package包/類
public static Intent prepareEditContactIntentWithSipAddress(int id, String sipUri) {
Intent intent = new Intent(Intent.ACTION_EDIT, Contacts.CONTENT_URI);
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
intent.setData(contactUri);
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
ContentValues sipAddressRow = new ContentValues();
sipAddressRow.put(Contacts.Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
sipAddressRow.put(SipAddress.SIP_ADDRESS, sipUri);
data.add(sipAddressRow);
intent.putParcelableArrayListExtra(Insert.DATA, data);
return intent;
}
示例2: deleteCalendar
import android.content.ContentUris; //導入方法依賴的package包/類
@SuppressWarnings("MissingPermission") // already requested in calling method
public void deleteCalendar(String calendarName) {
try {
Uri evuri = CalendarContract.Calendars.CONTENT_URI;
final ContentResolver contentResolver = cordova.getActivity().getContentResolver();
Cursor result = contentResolver.query(evuri, new String[]{CalendarContract.Calendars._ID, CalendarContract.Calendars.NAME, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME}, null, null, null);
if (result != null) {
while (result.moveToNext()) {
if (result.getString(1).equals(calendarName) || result.getString(2).equals(calendarName)) {
long calid = result.getLong(0);
Uri deleteUri = ContentUris.withAppendedId(evuri, calid);
contentResolver.delete(deleteUri, null, null);
}
}
result.close();
}
// also delete previously crashing calendars, see https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin/issues/241
deleteCrashingCalendars(contentResolver);
} catch (Throwable t) {
System.err.println(t.getMessage());
t.printStackTrace();
}
}
示例3: updateDatabase
import android.content.ContentUris; //導入方法依賴的package包/類
/**
* Updates the database if that is required (title and/or hide)
*/
public void updateDatabase(ContentResolver cr) {
boolean updateTitle = false;
if (dvdPart == 1) { // we only ever change the name of the _1.vob
if (newTitle == null) {
// reset title back to null if it is not.
updateTitle = archosTitle != null;
} else if (!newTitle.equals(archosTitle)) {
// change title to something new.
updateTitle = true;
}
}
if (updateTitle || hidden != newHide) {
ContentValues cv = new ContentValues();
if (updateTitle) {
cv.put(VideoStore.Video.VideoColumns.ARCHOS_TITLE, newTitle);
if (DBG) Log.d(TAG, "update " + file + " title: " + newTitle);
}
if (hidden != newHide) {
cv.put(VideoStore.Video.VideoColumns.ARCHOS_HIDE_FILE, newHide ? "1" : "0");
if (DBG) Log.d(TAG, "update " + file + " hide: " + (newHide ? "1" : "0"));
}
Uri uri = ContentUris.withAppendedId(VideoStore.Video.Media.EXTERNAL_CONTENT_URI, id);
cr.update(uri, cv, null, null);
}
}
示例4: handleImageOnKitKat
import android.content.ContentUris; //導入方法依賴的package包/類
@TargetApi(19)
private void handleImageOnKitKat(Intent data){
String imagePath=null;
Uri uri=data.getData();
if (DocumentsContract.isDocumentUri(getActivity(),uri)){
//如果是 document 類型的 Uri,則通過document id處理
String docId=DocumentsContract.getDocumentId(uri);
if ("com.android.providers.media.documents".equals(uri.getAuthority())){
String id=docId.split(":")[1]; //解析出數字格式的id
String selection=MediaStore.Images.Media._ID+"="+id;
imagePath=getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,selection);
}else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())){
Uri contentUri= ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
Long.valueOf(docId));
imagePath=getImagePath(contentUri,null);
}
}else if ("content".equalsIgnoreCase(uri.getScheme())){
//如果是content類型的Uri 則使用普通方式處理
imagePath=getImagePath(uri,null);
}else if ("file".equalsIgnoreCase(uri.getScheme())){
//如果是file類型的Uri,直接獲取圖片路徑即可
imagePath=uri.getPath();
}
displayImage(imagePath); //根據圖片路徑顯示圖片
}
示例5: insert
import android.content.ContentUris; //導入方法依賴的package包/類
public Uri insert(Uri uri, ContentValues values){
db = tOpenHelper.getWritableDatabase();
long id;
switch(sUriMatcher.match(uri)){
case ENTRY_LIST:
id = db.insert(TodoEntry.TABLE_NAME, null, values);
break;
case LABEL_LIST:
id = db.insert(TodoLabel.TABLE_NAME, null, values);
break;
case NOTIFICATION_LIST:
id = db.insert(TodoNotification.TABLE_NAME, null, values);
break;
default:
throw new IllegalArgumentException("Unsupported URI for insertion: " + uri);
}
Uri itemUri = ContentUris.withAppendedId(uri, id);
getContext().getContentResolver().notifyChange(itemUri, null);
return itemUri;
}
示例6: getContactInfo
import android.content.ContentUris; //導入方法依賴的package包/類
@Override
public ContactInfo getContactInfo(Context context, Cursor cursor) {
ContactInfo ci = new ContactInfo();
// Get values
ci.displayName = cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME));
ci.contactId = cursor.getLong(cursor.getColumnIndex(Contacts._ID));
ci.callerInfo.contactContentUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, ci.contactId);
ci.callerInfo.photoId = cursor.getLong(cursor.getColumnIndex(Contacts.PHOTO_ID));
int photoUriColIndex = cursor.getColumnIndex(Contacts.PHOTO_ID);
ci.status = cursor.getString(cursor.getColumnIndex(Contacts.CONTACT_STATUS));
ci.presence = cursor.getInt(cursor.getColumnIndex(Contacts.CONTACT_PRESENCE));
if (photoUriColIndex >= 0) {
String photoUri = cursor.getString(photoUriColIndex);
if (!TextUtils.isEmpty(photoUri)) {
ci.callerInfo.photoUri = Uri.parse(photoUri);
}
}
ci.hasPresence = !TextUtils.isEmpty(ci.status);
return ci;
}
示例7: getSongCountForAlbumInt
import android.content.ContentUris; //導入方法依賴的package包/類
public static final int getSongCountForAlbumInt(final Context context, final long id) {
int songCount = 0;
if (id == -1) {
return songCount;
}
Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, id);
Cursor cursor = context.getContentResolver().query(uri,
new String[]{MediaStore.Audio.AlbumColumns.NUMBER_OF_SONGS}, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
if (!cursor.isAfterLast()) {
if (!cursor.isNull(0)) {
songCount = cursor.getInt(0);
}
}
cursor.close();
cursor = null;
}
return songCount;
}
示例8: preHoneycombGetContactInfo
import android.content.ContentUris; //導入方法依賴的package包/類
/**
* For versions before Honeycomb, we get all the contact info from the same table.
*/
public void preHoneycombGetContactInfo(Cursor cursor) {
if (cursor.moveToFirst()) {
contactName = guardCursorGetString(cursor, NAME_INDEX);
phoneNumber = guardCursorGetString(cursor, NUMBER_INDEX);
int contactId = cursor.getInt(PERSON_INDEX);
Uri cUri = ContentUris.withAppendedId(Contacts.People.CONTENT_URI, contactId);
contactPictureUri = cUri.toString();
String emailId = guardCursorGetString(cursor, EMAIL_INDEX);
emailAddress = getEmailAddress(emailId);
}
}
示例9: onListItemClick
import android.content.ContentUris; //導入方法依賴的package包/類
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Uri noteUri = ContentUris.withAppendedId(getIntent().getData(), id);
String action = getIntent().getAction();
if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
// The caller is waiting for us to return a note selected by
// the user. The have clicked on one, so return it now.
setResult(RESULT_OK, new Intent().setData(noteUri));
} else {
// Launch activity to view/edit the currently selected item
startActivity(new Intent(Intent.ACTION_EDIT, noteUri));
}
}
示例10: getContentUriForImageFromMediaStore
import android.content.ContentUris; //導入方法依賴的package包/類
private static Uri getContentUriForImageFromMediaStore(Context context, String path) {
ContentResolver resolver = context.getContentResolver();
//Uri photoUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
// to handle hidden images
Uri photoUri = MediaStore.Files.getContentUri("external");
Cursor cursor = resolver.query(photoUri,
new String[]{BaseColumns._ID},
MediaStore.MediaColumns.DATA + " = ?",
new String[]{path}, null);
if (cursor == null) {
return Uri.parse(path);
}
cursor.moveToFirst();
if (cursor.isAfterLast()) {
cursor.close();
// insert system media db
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, path);
values.put(MediaStore.Images.Media.MIME_TYPE, MediaType.getMimeType(path));
return context.getContentResolver().insert(photoUri, values);
} else {
long id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
Uri uri = ContentUris.withAppendedId(photoUri, id);
cursor.close();
return uri;
}
}
示例11: createUri
import android.content.ContentUris; //導入方法依賴的package包/類
public synchronized Uri createUri(@NonNull byte[] blob) {
try {
long id = Math.abs(SecureRandom.getInstance("SHA1PRNG").nextLong());
cache.put(id, blob);
Uri uniqueUri = Uri.withAppendedPath(CONTENT_URI, String.valueOf(System.currentTimeMillis()));
return ContentUris.withAppendedId(uniqueUri, id);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
示例12: notifyContentChanged
import android.content.ContentUris; //導入方法依賴的package包/類
/**
* Notify of a change through both URIs (/my_downloads and /all_downloads)
*
* @param uri either URI for the changed download(s)
* @param uriMatch the match ID from {@link #sURIMatcher}
*/
private void notifyContentChanged(final Uri uri, int uriMatch) {
Long downloadId = null;
if (uriMatch == MY_DOWNLOADS_ID || uriMatch == ALL_DOWNLOADS_ID) {
downloadId = Long.parseLong(getDownloadIdFromUri(uri));
}
for (Uri uriToNotify : BASE_URIS) {
if (downloadId != null) {
uriToNotify = ContentUris.withAppendedId(uriToNotify, downloadId);
}
getContext().getContentResolver().notifyChange(uriToNotify, null);
}
}
示例13: insert
import android.content.ContentUris; //導入方法依賴的package包/類
@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
// COMPLETED (1) Get access to the task database (to write new data to)
final SQLiteDatabase db = mTaskDbHelper.getWritableDatabase();
// COMPLETED (2) Write URI matching code to identify the match for the tasks directory
int match = sUriMatcher.match(uri);
Uri returnUri;
switch (match) {
case TASKS:
// COMPLETED (3) Insert new values into the database
long id = db.insert(TaskEntry.TABLE_NAME, null, values);
if (id > 0) {
returnUri = ContentUris.withAppendedId(TaskEntry.CONTENT_URI, id);
} else {
throw new SQLException("Failed to insert row " + uri);
}
break;
// COMPLETED (4) Set the value for the returnedUri and write the default case for unknown URI's
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
// COMPLETED (5) Notify the resolver if the uri has been changed, and return the newly inserted URI
getContext().getContentResolver().notifyChange(uri, null);
return returnUri;
}
示例14: onCreate
import android.content.ContentUris; //導入方法依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = this.getArguments();
if(bundle != null){
mode = bundle.getString("mode");
if(bundle.containsKey("entry_id")){
entryId = bundle.getLong("entry_id");
} else {
entryId = null;
}
}
if(savedInstanceState != null){
myCalendar = (Calendar) savedInstanceState.getSerializable("calendar");
chosenLabelId = savedInstanceState.getLong("chosen_label_id", -1L);
title = savedInstanceState.getString("title");
} else {
myCalendar = Calendar.getInstance();
// Default for new entry
myCalendar.set(Calendar.HOUR_OF_DAY, 23);
myCalendar.set(Calendar.MINUTE, 59);
myCalendar.set(Calendar.SECOND, 0);
if (mode.equals("edit_entry")){
Uri entryUri = ContentUris.withAppendedId(ToduleDBContract.TodoEntry.CONTENT_ID_URI_BASE, entryId);
Cursor cr = getContext().getContentResolver().query(entryUri, TodoEntry.PROJECTION_ALL, null, null, TodoEntry.SORT_ORDER_DEFAULT);
cr.moveToFirst();
long dueDateInMillis = cr.getLong(cr.getColumnIndexOrThrow(TodoEntry.COLUMN_NAME_DUE_DATE));
title = cr.getString(cr.getColumnIndexOrThrow(TodoEntry.COLUMN_NAME_TITLE));
description = cr.getString(cr.getColumnIndexOrThrow(TodoEntry.COLUMN_NAME_DESCRIPTION));
if(cr.isNull(cr.getColumnIndexOrThrow(TodoEntry.COLUMN_NAME_LABEL))){
chosenLabelId = -1L;
} else{
chosenLabelId = cr.getLong(cr.getColumnIndexOrThrow(TodoEntry.COLUMN_NAME_LABEL));
}
myCalendar.setTimeInMillis(dueDateInMillis);
cr.close();
}
}
}
示例15: getSongFileUri
import android.content.ContentUris; //導入方法依賴的package包/類
public static Uri getSongFileUri(int songId) {
return ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, songId);
}