Sofia API Reference

  • Package Index
  • Class Index
  • Packages
  • sofia.app
  • sofia.content
    • Classes
    • ContentViewer
    • MediaChooser
    • MediaUtils
    • PhotoCamera
  • sofia.data
  • sofia.graphics
  • sofia.util
  • sofia.view
  • sofia.widget

public class
MediaUtils

extends Object

Inheritance

  • java.lang.Object
    • sofia.content.MediaUtils

Class Overview

Utility methods to make working with the built-in Android media gallery easier for students. TODO These might benefit from some refactoring now.


Summary

Public Methods
static List<Uri> getExternalMediaUris(ContentResolver resolver, String type)

Gets a list of all external media (stored on the device's SD card) that has the specified type.

static String pathForMediaUri(ContentResolver resolver, Uri uri)
Converts a media Uri, such as one received by an activity's onActivityResult method after popping up an image chooser, to a path on the device's file system that can be used to open or manipulate the media file.
static Uri uriForMediaWithFilename(ContentResolver resolver, String filename)

Most students will never need to call this method -- it is intended for internal and advanced usage.

Methods inherited from class java.lang.Object
Object clone()
boolean equals(Object arg0)
void finalize()
final Class<?> getClass()
int hashCode()
final void notify()
final void notifyAll()
String toString()
final void wait()
final void wait(long arg0, int arg1)
final void wait(long arg0)

Public Methods

public static List<Uri> getExternalMediaUris (ContentResolver resolver, String type)

Gets a list of all external media (stored on the device's SD card) that has the specified type. The type can be a complete MIME type (such as "image/jpeg") or one with a wildcard (such as "image/*" to select all images).

The list returned by this method contains Uri objects; in order to get the path that corresponds to that Uri so that you can open the file, pass it to the pathForMediaUri(ContentResolver, Uri) method.

Parameters
resolver
the content resolver used to find the content; this can be obtained by calling getContentResolver() from within the activity
type
the MIME type of the media to list
Returns

a List containing the Uris of all the matching media on the device's external storage

public static String pathForMediaUri (ContentResolver resolver, Uri uri)

Converts a media Uri, such as one received by an activity's onActivityResult method after popping up an image chooser, to a path on the device's file system that can be used to open or manipulate the media file.

Parameters
resolver
the content resolver used to find the content; this can be obtained by calling getContentResolver() from within the activity
uri
the Uri that represents the location of the media to get the path for
Returns

the path to the file represented by the media Uri, or null if the Uri was invalid

public static Uri uriForMediaWithFilename (ContentResolver resolver, String filename)

Most students will never need to call this method -- it is intended for internal and advanced usage.

Gets a Uri that represents a media item with the specified filename.

No MIME type is required here because the filename of the media (for example, "foo.jpg" or "bar.png") would typically also distinguish the type. However, if multiple media have the same filename, only the first one that is found will be returned, and the ordering of what is "first" is entirely dependent on the internal database ordering, and therefore should not be relied upon. If this is a problem, use a longer path segment than just the filename.

Parameters
resolver
the content resolver used to find the content; this can be obtained by calling getContentResolver() from within the activity
filename
the filename of the media to find
Returns

a Uri that represents the media being requested, or null if no media with that filename could be found