List of usage examples for android.net Uri toString
public abstract String toString();
From source file:Main.java
public static Reader getUri(Uri uri) throws IOException { return getUri(new URL(uri.toString())); }
From source file:Main.java
private static void appendUri(StringBuilder sb, Uri uri) { append(sb, uri == null ? null : uri.toString()); }
From source file:Main.java
/** * Checks if file passed is an image/* ww w . j a v a 2 s. c o m*/ * @param file * @return true/false */ public static boolean isImage(File file) { Uri selectedUri = Uri.fromFile(file); String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString().toLowerCase()); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); return (mimeType != null && mimeType.startsWith("image/")); }
From source file:Main.java
public static int getOrientation(final Uri photoUri) { ExifInterface exifInterface = null;/*from www.java2 s . co m*/ try { exifInterface = new ExifInterface(photoUri.toString()); } catch (IOException e) { e.printStackTrace(); } return exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); }
From source file:Main.java
public static String queryAudioName(Context context, Uri name) { String audioId;//from w w w .j a va 2 s. co m String uriName = name.toString(); uriName = uriName.substring(uriName.lastIndexOf("/") + 1); Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); int counter = cursor.getCount(); for (int j = 0; j < counter; j++) { audioId = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); if (uriName.equals(audioId)) { uriName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); } else { Ringtone ringtone = RingtoneManager.getRingtone(context, name); uriName = ringtone.getTitle(context); break; } cursor.moveToNext(); } cursor.close(); } else { try { Ringtone ringtone = RingtoneManager.getRingtone(context, name); uriName = ringtone.getTitle(context); } catch (Exception e) { return uriName; } } return uriName; }
From source file:Main.java
public static InputStream getISFromURI(Context context, Uri contentURI) { ContentResolver res = context.getContentResolver(); Uri uri = Uri.parse(contentURI.toString()); InputStream is = null;/*w w w. j a v a 2 s .com*/ try { is = res.openInputStream(uri); } catch (FileNotFoundException e) { jlog(e); } return is; }
From source file:Main.java
public static String resolveFileName(Uri uri, Activity activity) { String filename = null;//from w w w. j av a 2s. com String uriString = uri.toString(); if (uriString.startsWith("content://")) { Cursor cursor = null; try { cursor = activity.getContentResolver().query(uri, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { String mimeType = MimeTypeMap.getSingleton() .getExtensionFromMimeType(activity.getContentResolver().getType(uri)); filename = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); if (mimeType != null && !filename.endsWith("." + mimeType)) { filename += "." + mimeType; } } } finally { if (cursor != null) { cursor.close(); } } } else if (uriString.startsWith("file://")) { filename = (new File(uriString)).getName(); } return filename; }
From source file:Main.java
public static String pathFromUri(Uri fileUri) { String filePath = null;/*from www .j a v a 2 s . c om*/ if (fileUri != null && "file".equals(fileUri.getScheme())) { filePath = fileUri.toString().substring("file://".length()); } return filePath; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.FriendAcceptObj.java
public static JSONObject json(Uri uri) { JSONObject obj = new JSONObject(); try {/*from ww w. j a v a 2s . c o m*/ obj.put(URI, uri.toString()); } catch (JSONException e) { } return obj; }
From source file:Main.java
public static void IcsMakeNewCalendarEntry(String title, String description, String location, long startTime, long endTime, int allDay, int hasAlarm, int calendarId, int selectedReminderValue) { ContentResolver cr = activityObj.getContentResolver(); ContentValues values = new ContentValues(); values.put(Events.DTSTART, startTime); values.put(Events.DTEND, endTime);//from ww w. ja v a2 s .c o m values.put(Events.TITLE, title); values.put(Events.DESCRIPTION, description); values.put(Events.CALENDAR_ID, calendarId); if (allDay == 1) { values.put(Events.ALL_DAY, true); } if (hasAlarm == 1) { values.put(Events.HAS_ALARM, true); } //Get current timezone values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID()); Log.i(DEBUG_TAG, "Timezone retrieved=>" + TimeZone.getDefault().getID()); Uri uri = cr.insert(Events.CONTENT_URI, values); Log.i(DEBUG_TAG, "Uri returned=>" + uri.toString()); // get the event ID that is the last element in the Uri long eventID = Long.parseLong(uri.getLastPathSegment()); if (hasAlarm == 1) { ContentValues reminders = new ContentValues(); reminders.put(Reminders.EVENT_ID, eventID); reminders.put(Reminders.METHOD, Reminders.METHOD_ALERT); reminders.put(Reminders.MINUTES, selectedReminderValue); Uri uri2 = cr.insert(Reminders.CONTENT_URI, reminders); } }