List of usage examples for android.net Uri withAppendedPath
public static Uri withAppendedPath(Uri baseUri, String pathSegment)
From source file:Main.java
/** * Gets a contact number and then displays the name of contact in the DP * * @param context context of the activity from which it was called. * @param contactNumber a string representation of the contact number * @return returns the number if no contact exist. *///from w w w . j a v a 2 s . c om public static String getContactName(Context context, String contactNumber) { String displayName = null; Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(contactNumber)); Cursor cur = context.getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); if (cur != null && cur.moveToFirst()) { displayName = cur.getString(cur.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); } else { displayName = contactNumber; } if (!cur.isClosed()) { cur.close(); } return displayName; }
From source file:Main.java
public static Uri pathToContentUri(Context context, String imagePath) { Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[] { "_id" }, "_data=? ", new String[] { imagePath }, null); if (cursor != null && cursor.moveToFirst()) { int imageFile1 = cursor.getInt(cursor.getColumnIndex("_id")); Uri values1 = Uri.parse("content://media/external/images/media"); return Uri.withAppendedPath(values1, "" + imageFile1); } else {/*from w w w . j a v a 2s.com*/ File imageFile = new File(imagePath); if (imageFile.exists()) { ContentValues values = new ContentValues(); values.put("_data", imagePath); Uri baseUri = Media.EXTERNAL_CONTENT_URI; return context.getContentResolver().insert(baseUri, values); } else { return null; } } }
From source file:Main.java
public static Uri getAudioContentUri(Context context, File file) { String filePath = file.getAbsolutePath(); Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media._ID }, MediaStore.Audio.Media.DATA + "=?", new String[] { filePath }, null); cursor.moveToFirst();//from w w w.j av a 2 s . c o m int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID)); Uri baseUri = Uri.parse("content://media/external/audio/media"); return Uri.withAppendedPath(baseUri, "" + id); }
From source file:Main.java
public static String getContactName(Context context, String number) { String name = null;//from w w w.j av a2s .c o m // define the columns I want the query to return String[] projection = new String[] { Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? ContactsContract.Contacts.DISPLAY_NAME_PRIMARY : ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.PhoneLookup._ID }; // encode the phone number and build the filter URI Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); // query time Cursor cursor = context.getContentResolver().query(contactUri, projection, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); Log.v("getContactName", "Started uploadcontactphoto: Contact Found @ " + number); Log.v("getContactName", "Started uploadcontactphoto: Contact name = " + name); } else { Log.v("getContactName", "Contact Not Found @ " + number); } cursor.close(); } return name; }
From source file:Main.java
public static Cursor getContactProfile(Context context, String number) { if (TextUtils.isEmpty(number)) { return null; }//from w w w . java 2s.c om ContentResolver cr = context.getContentResolver(); Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); return cr.query(uri, CONTACT_PROJ, null, null, null); }
From source file:Main.java
public static Uri getBitmapFromImageId(Activity activity, int imageId) { String[] tinyImgPprojection = { MediaStore.Images.Thumbnails._ID }; Cursor tinyCursor = Thumbnails.queryMiniThumbnail(activity.getContentResolver(), imageId, Thumbnails.MINI_KIND, tinyImgPprojection); if (tinyCursor.getCount() != 0) { tinyCursor.moveToFirst();/* www.j ava2 s .c o m*/ int tinyImgId = tinyCursor.getInt(tinyCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID)); tinyCursor.close(); return Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, String.valueOf(tinyImgId)); } else { tinyCursor.close(); return null; } }
From source file:Main.java
/** * Looks up a contacts display name by contact id - if not found, the * address (phone number) will be formatted and returned instead. *//* ww w . ja v a2s .co m*/ public static String getPersonName(Context context, String id, String address) { // Check for id, if null return the formatting phone number as the name if (id == null || "".equals(id.trim())) { if (address != null && !"".equals(address.trim())) { return PhoneNumberUtils.formatNumber(address); } else { return null; } } Cursor cursor = context.getContentResolver().query(Uri.withAppendedPath(Contacts.CONTENT_URI, id), new String[] { Contacts.DISPLAY_NAME }, null, null, null); if (cursor != null) { try { if (cursor.getCount() > 0) { cursor.moveToFirst(); String name = cursor.getString(0); return name; } } finally { cursor.close(); } } if (address != null) { return PhoneNumberUtils.formatNumber(address); } return null; }
From source file:Main.java
public static byte[] getPersonPhoto(Context context, String id) { if (id == null) return null; byte photo[] = null; Cursor cursor = context.getContentResolver().query(Uri.withAppendedPath(Contacts.Photos.CONTENT_URI, id), new String[] { PhotosColumns.DATA }, null, null, null); if (cursor != null) { try {//from www. j a va2s .co m if (cursor.getCount() > 0) { cursor.moveToFirst(); photo = cursor.getBlob(0); if (photo != null) { return photo; // Log.v("Found photo for person: " + id); // bitmap = BitmapFactory.decodeStream(new // ByteArrayInputStream(photo)); } } } finally { cursor.close(); } } return photo; }
From source file:can.yrt.onebusaway.RouteInfoActivity.java
public static Intent makeIntent(Context context, String routeId) { Intent myIntent = new Intent(context, RouteInfoActivity.class); myIntent.setData(Uri.withAppendedPath(ObaContract.Routes.CONTENT_URI, routeId)); return myIntent; }
From source file:Main.java
/** * method used to lookup the id of a contact photo id * * @param context//from w ww .j a v a 2s. c o m * a context object used to get a content resolver * @param phoneNumber * the phone number of the contact * * @return the id of the contact */ public static long lookupPhotoId(Context context, String phoneNumber) { long mPhotoId = -1; Uri mLookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); String[] mProjection = new String[2]; mProjection[0] = PhoneLookup._ID; mProjection[1] = PhoneLookup.PHOTO_ID; Cursor mCursor = context.getContentResolver().query(mLookupUri, mProjection, null, null, null); if (mCursor.getCount() > 0) { mCursor.moveToFirst(); mPhotoId = mCursor.getLong(mCursor.getColumnIndex(PhoneLookup._ID)); mCursor.close(); } return mPhotoId; }