List of usage examples for android.net Uri withAppendedPath
public static Uri withAppendedPath(Uri baseUri, String pathSegment)
From source file:com.android.mms.ui.ComposeMessageActivity.java
private Uri getContactUriForEmail(String emailAddress) { Cursor cursor = SqliteWrapper.query(this, getContentResolver(), Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(emailAddress)), new String[] { Email.CONTACT_ID, Contacts.DISPLAY_NAME }, null, null, null); if (cursor != null) { try {/*from www .jav a 2 s . c om*/ while (cursor.moveToNext()) { String name = cursor.getString(1); if (!TextUtils.isEmpty(name)) { return ContentUris.withAppendedId(Contacts.CONTENT_URI, cursor.getLong(0)); } } } finally { cursor.close(); } } return null; }
From source file:org.kontalk.ui.ComposeMessageFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // image from storage/picture from camera // since there are like up to 3 different ways of doing this... if (requestCode == SELECT_ATTACHMENT_OPENABLE || requestCode == SELECT_ATTACHMENT_PHOTO) { if (resultCode == Activity.RESULT_OK) { Uri[] uris = null;/*w w w. ja v a2s. c om*/ String[] mimes = null; // returning from camera if (data == null) { if (mCurrentPhoto != null) { Uri uri = Uri.fromFile(mCurrentPhoto); // notify media scanner Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(uri); getActivity().sendBroadcast(mediaScanIntent); mCurrentPhoto = null; uris = new Uri[] { uri }; } } else { if (mCurrentPhoto != null) { mCurrentPhoto.delete(); mCurrentPhoto = null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && data.getClipData() != null) { ClipData cdata = data.getClipData(); uris = new Uri[cdata.getItemCount()]; for (int i = 0; i < uris.length; i++) { ClipData.Item item = cdata.getItemAt(i); uris[i] = item.getUri(); } } else { uris = new Uri[] { data.getData() }; mimes = new String[] { data.getType() }; } // SAF available, request persistable permissions if (MediaStorage.isStorageAccessFrameworkAvailable()) { for (Uri uri : uris) { if (uri != null && !"file".equals(uri.getScheme())) { MediaStorage.requestPersistablePermissions(getActivity(), uri); } } } } for (int i = 0; uris != null && i < uris.length; i++) { Uri uri = uris[i]; String mime = (mimes != null && mimes.length >= uris.length) ? mimes[i] : null; if (mime == null || mime.startsWith("*/") || mime.endsWith("/*")) { mime = MediaStorage.getType(getActivity(), uri); Log.v(TAG, "using detected mime type " + mime); } if (ImageComponent.supportsMimeType(mime)) sendBinaryMessage(uri, mime, true, ImageComponent.class); else if (VCardComponent.supportsMimeType(mime)) sendBinaryMessage(uri, VCardComponent.MIME_TYPE, false, VCardComponent.class); else Toast.makeText(getActivity(), R.string.send_mime_not_supported, Toast.LENGTH_LONG).show(); } } // operation aborted else { // delete photo :) if (mCurrentPhoto != null) { mCurrentPhoto.delete(); mCurrentPhoto = null; } } } // contact card (vCard) else if (requestCode == SELECT_ATTACHMENT_CONTACT) { if (resultCode == Activity.RESULT_OK) { Uri uri = data.getData(); if (uri != null) { // get lookup key final Cursor c = getActivity().getContentResolver().query(uri, new String[] { Contacts.LOOKUP_KEY }, null, null, null); if (c != null) { try { c.moveToFirst(); String lookupKey = c.getString(0); Uri vcardUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); sendBinaryMessage(vcardUri, VCardComponent.MIME_TYPE, false, VCardComponent.class); } finally { c.close(); } } } } } }
From source file:org.odk.collect.android.logic.FormRelationsManager.java
/** * Converts an id number to Uri for an instance. * * @param id Id number/*from ww w . j a v a2 s .c om*/ * @return Returns the corresponding InstanceProvider Uri. */ private static Uri getInstanceUriFromId(long id) { return Uri.withAppendedPath(InstanceColumns.CONTENT_URI, String.valueOf(id)); }
From source file:org.odk.collect.android.logic.FormRelationsManager.java
/** * Converts an id number to Uri for a form. * * @param id Id number//from w w w .j a v a 2 s . c o m * @return Returns the corresponding FormProvider Uri. */ private static Uri getFormUriFromId(long id) { return Uri.withAppendedPath(FormsColumns.CONTENT_URI, String.valueOf(id)); }
From source file:com.colorchen.qbase.utils.FileUtil.java
/** * ??uri// w ww . ja v a2 s . c o m * * @param context * @param imageFile * @return */ public static Uri getImageContentUri(Context context, File imageFile) { String filePath = imageFile.getAbsolutePath(); Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Images.Media._ID }, MediaStore.Images.Media.DATA + "=? ", new String[] { filePath }, null); if (cursor != null && cursor.moveToFirst()) { int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID)); Uri baseUri = Uri.parse("content://media/external/images/media"); return Uri.withAppendedPath(baseUri, "" + id); } else { if (imageFile.exists()) { ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.DATA, filePath); return context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } else { return null; } } }
From source file:com.vegnab.vegnab.MainVNActivity.java
void logPurchaseActivity(ContentValues cv) { // create a new record with whatever fields are provided in ContentValues Uri uri, purchUri = Uri.withAppendedPath(ContentProvider_VegNab.CONTENT_URI, "purchases"); ContentResolver rs = getContentResolver(); // create a new record uri = rs.insert(purchUri, cv);//from w ww. j a v a 2 s . c o m mNewPurcRecId = Long.parseLong(uri.getLastPathSegment()); if (LDebug.ON) Log.d(LOG_TAG, "mNewPurcRecId of new record stored in DB: " + mNewPurcRecId); }
From source file:com.vegnab.vegnab.MainVNActivity.java
void logPurchaseActivity(Purchase p, IabResult result, boolean isConsumed, String notes) { Uri uri, purchUri = Uri.withAppendedPath(ContentProvider_VegNab.CONTENT_URI, "purchases"); ContentResolver rs = getContentResolver(); ContentValues contentValues = new ContentValues(); if (p == null) { contentValues.put("ProductIdCode", "(purchase object is null)"); contentValues.put("Type", "null"); contentValues.put("PurchaseState", -2); // purchase is null } else {//from w w w.j a v a2s . com String sku = p.getSku(); contentValues.put("ProductIdCode", sku); // also called 'SKU' contentValues.put("DevPayload", p.getDeveloperPayload()); contentValues.put("Type", p.getItemType()); // "inapp" for an in-app product or "subs" for subscriptions. contentValues.put("OrderIDCode", p.getOrderId()); // corresponds to the Google payments order ID contentValues.put("PkgName", p.getPackageName()); contentValues.put("Signature", p.getSignature()); contentValues.put("Token", p.getToken()); // uniquely identifies a purchase for a given item and user pair contentValues.put("PurchaseState", p.getPurchaseState()); // standard: 0 (purchased), 1 (canceled), or 2 (refunded). or nonstandard: -1 (initiated), -2 (null) SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); long t = p.getPurchaseTime(); contentValues.put("PurchaseTime", dateTimeFormat.format(new Date(t))); contentValues.put("PurchJSON", p.getOriginalJson()); try { // inventory object may not exist yet if (mInventory.hasDetails(sku)) { SkuDetails skuDetails = mInventory.getSkuDetails(sku); contentValues.put("Price", skuDetails.getPrice()); contentValues.put("Description", skuDetails.getDescription()); contentValues.put("Title", skuDetails.getTitle()); } else { contentValues.putNull("Price"); contentValues.putNull("Description"); contentValues.putNull("Title"); } } catch (Exception e) { contentValues.putNull("Price"); contentValues.putNull("Description"); contentValues.putNull("Title"); } } contentValues.put("Consumed", isConsumed ? 1 : 0); if (result == null) { contentValues.putNull("IABResponse"); contentValues.putNull("IABMessage"); } else { contentValues.put("IABResponse", result.getResponse()); contentValues.put("IABMessage", result.getMessage()); } if (notes == null) { contentValues.putNull("Notes"); } else { contentValues.put("Notes", notes); } // create a new record uri = rs.insert(purchUri, contentValues); mNewPurcRecId = Long.parseLong(uri.getLastPathSegment()); if (LDebug.ON) Log.d(LOG_TAG, "mNewPurcRecId of new record stored in DB: " + mNewPurcRecId); }
From source file:com.chen.mail.utils.NotificationUtils.java
private static Bitmap getContactIcon(final Context context, final String displayName, final String senderAddress, final Folder folder) { if (senderAddress == null) { return null; }/*from w w w . j av a2 s.c o m*/ Bitmap icon = null; final List<Long> contactIds = findContacts(context, Arrays.asList(new String[] { senderAddress })); // Get the ideal size for this icon. final Resources res = context.getResources(); final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); if (contactIds != null) { for (final long id : contactIds) { final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); final Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY); final Cursor cursor = context.getContentResolver().query(photoUri, new String[] { Photo.PHOTO }, null, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { final byte[] data = cursor.getBlob(0); if (data != null) { icon = BitmapFactory.decodeStream(new ByteArrayInputStream(data)); if (icon != null && icon.getHeight() < idealIconHeight) { // We should scale this image to fit the intended size icon = Bitmap.createScaledBitmap(icon, idealIconWidth, idealIconHeight, true); } if (icon != null) { break; } } } } finally { cursor.close(); } } } } if (icon == null) { // Make a colorful tile! final ImageCanvas.Dimensions dimensions = new ImageCanvas.Dimensions(idealIconWidth, idealIconHeight, ImageCanvas.Dimensions.SCALE_ONE); icon = new LetterTileProvider(context).getLetterTile(dimensions, displayName, senderAddress); } if (icon == null) { // Icon should be the default mail icon. icon = getDefaultNotificationIcon(context, folder, false /* single new message */); } return icon; }
From source file:com.indeema.mail.utils.NotificationUtils.java
private static Bitmap getContactIcon(final Context context, final String displayName, final String senderAddress, final Folder folder) { if (senderAddress == null) { return null; }/* w w w . j av a 2s .co m*/ Bitmap icon = null; final List<Long> contactIds = findContacts(context, Arrays.asList(new String[] { senderAddress })); // Get the ideal size for this icon. final Resources res = context.getResources(); final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); if (contactIds != null) { for (final long id : contactIds) { final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); final Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY); final Cursor cursor = context.getContentResolver().query(photoUri, new String[] { Photo.PHOTO }, null, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { final byte[] data = cursor.getBlob(0); if (data != null) { icon = BitmapFactory.decodeStream(new ByteArrayInputStream(data)); if (icon != null && icon.getHeight() < idealIconHeight) { // We should scale this image to fit the intended size icon = Bitmap.createScaledBitmap(icon, idealIconWidth, idealIconHeight, true); } if (icon != null) { break; } } } } finally { cursor.close(); } } } } if (icon == null) { // Make a colorful tile! final Dimensions dimensions = new Dimensions(idealIconWidth, idealIconHeight, Dimensions.SCALE_ONE); icon = new LetterTileProvider(context).getLetterTile(dimensions, displayName, senderAddress); } if (icon == null) { // Icon should be the default mail icon. icon = getDefaultNotificationIcon(context, folder, false /* single new message */); } return icon; }
From source file:net.kidlogger.kidlogger.KLService.java
private String getNameFromContacts(String number, boolean record) { ContentResolver cr = getContentResolver(); // Get Name from Contacts Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); Cursor curId = cr.query(uri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); if (curId == null) { if (record) return "unknown"; else//from w w w .ja va 2s . co m return number + " unknown"; } if (curId.getCount() > 0) { while (curId.moveToNext()) { String name = curId.getString(curId.getColumnIndex(PhoneLookup.DISPLAY_NAME)); if (!name.equals("")) { if (record) return name; else return number + " " + name; } } } curId.close(); if (record) return "unknown"; else return number + " unknown"; }