List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:Main.java
public static int deleteById(Context context, Uri uri, long id) { return context.getContentResolver().delete(ContentUris.withAppendedId(uri, id), null, null); }
From source file:Main.java
public static Uri getContactUri(String contactId) { return ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(contactId)); }
From source file:Main.java
public static Uri getSongUri(int id) { String albumId = String.valueOf(id); Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart"); Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, Integer.valueOf(albumId)); return albumArtUri; }
From source file:Main.java
public static Intent createOpenCalendarEventIntent(int eventId, DateTime from, DateTime to) { Intent intent = createCalendarIntent(Intent.ACTION_VIEW); intent.setData(ContentUris.withAppendedId(Events.CONTENT_URI, eventId)); intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, from.getMillis()); intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, to.getMillis()); return intent; }
From source file:Main.java
public static Uri getUriFromPath(Context context, String path) { String fileName = "file:///sdcard/DCIM/Camera/2013_07_07_12345.jpg"; Uri fileUri = Uri.parse(fileName);/*from w w w . jav a2 s . com*/ String filePath = fileUri.getPath(); Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, "_data = '" + filePath + "'", null, null); cursor.moveToNext(); int id = cursor.getInt(cursor.getColumnIndex("_id")); Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id); return uri; }
From source file:Main.java
public static Uri getAlbumArtUri(long paramInt) { return ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"), paramInt); }
From source file:Main.java
public static boolean deleteArtwork(Context c, long albumId) { return c.getContentResolver().delete(ContentUris.withAppendedId(ARTWORK_URI, albumId), null, null) > 0; }
From source file:Main.java
public static Bitmap getArtworkQuick(Context context, long album_id, int w, int h) { // NOTE: There is in fact a 1 pixel border on the right side in the // ImageView/*w w w. j ava 2 s .c o m*/ // used to display this drawable. Take it into account now, so we don't // have to // scale later. w -= 1; ContentResolver res = context.getContentResolver(); Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id); if (uri != null) { ParcelFileDescriptor fd = null; try { fd = res.openFileDescriptor(uri, "r"); int sampleSize = 1; // Compute the closest power-of-two scale factor // and pass that to sBitmapOptionsCache.inSampleSize, which will // result in faster decoding and better quality sBitmapOptionsCache.inJustDecodeBounds = true; BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor(), null, sBitmapOptionsCache); int nextWidth = sBitmapOptionsCache.outWidth >> 1; int nextHeight = sBitmapOptionsCache.outHeight >> 1; while (nextWidth > w && nextHeight > h) { sampleSize <<= 1; nextWidth >>= 1; nextHeight >>= 1; } sBitmapOptionsCache.inSampleSize = sampleSize; sBitmapOptionsCache.inJustDecodeBounds = false; Bitmap b = BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor(), null, sBitmapOptionsCache); if (b != null) { // finally rescale to exactly the size we need if (sBitmapOptionsCache.outWidth != w || sBitmapOptionsCache.outHeight != h) { Bitmap tmp = Bitmap.createScaledBitmap(b, w, h, true); // Bitmap.createScaledBitmap() can return the same // bitmap if (tmp != b) b.recycle(); b = tmp; } } return b; } catch (FileNotFoundException e) { } finally { try { if (fd != null) fd.close(); } catch (IOException e) { } } } return null; }
From source file:Main.java
public static Intent prepareEditContactIntent(int id) { Intent intent = new Intent(Intent.ACTION_EDIT, Contacts.CONTENT_URI); Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id); intent.setData(contactUri);/*from w ww . j a v a 2 s .c o m*/ return intent; }
From source file:Main.java
private static void syncContactHiResPhoto(Context context, long rawContactId) { final String serviceName = "com.google.android.syncadapters.contacts." + "SyncHighResPhotoIntentService"; final String servicePackageName = "com.google.android.syncadapters.contacts"; final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); final Intent intent = new Intent(); intent.setClassName(servicePackageName, serviceName); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(uri, RawContacts.CONTENT_ITEM_TYPE); try {//from w ww.j ava 2 s .com context.startService(intent); } catch (Exception e) { } }