I/O operations
You can use the following methods for performing I/O operations with ringtones:
Load ringtones
You can load ringtones from files, URLs and from byte arrays.
Load a ringtone from file:
public static Ringtone openRingtone(String format, byte[] bytes)
- format is a format from the right column in the table of supported formats.
- bytes is a byte array, containing ringtone data in a valid format.
public static Ringtone openRingtone(String format, InputStream stream) throws IOException
- format is a format from the right column in the table of supported formats.
- stream is an InputStream instance, where a ringtone can be loaded from.
public static Ringtone openRingtone(String format, String filename) throws IOException
- format is a format from the right column in the table of supported formats.
- filename is a name of the file in a local file system.
Starting with version 2.3 the
format parameter is optional. This means that Ringtone Creator is able to determine the format of the provided file automatically. If the file doesn't seem to correspond to any format, a
RingtoneParseException gets thrown.
RingtoneParseException is a RuntimeException instance and doesn't always need to be caught.
Save ringtones
public void saveRingtone(String format, OutputStream stream) throws IOException
- format is a format from the right column in the table of supported formats plus an optional OPTION parameter or several concatenated OPTIONs.
- filename is an OutputStream instance to write the resulting ringtone to.
public void saveRingtone(String format, String filename) throws IOException
- format is a format from the right column in the table of supported formats plus an optional OPTION parameter or several concatenated OPTIONs.
- filename is a name of the file in a local file system
public final byte[] getRingtoneBytes(String format) throws RingtoneConvertException
- format is a format from the right column in the table of supported formats plus an optional OPTION parameter or several concatenated OPTIONs.
RingtoneConvertException is a RuntimeException instance and doesn't always need to be caught.
Determine ringtone format
You can determine ringtone format by its bytes.
Get ringtone format:
public static final String getFormat(byte[] bytes) throws IOException, RingtoneParseException
- bytes is a byte array, containing ringtone data in a valid format.
RingtoneParseException is a RuntimeException instance and doesn't always need to be caught.
You can pass obtained string format value as the first parameter to openRingtone(), saveRingtone() or getRingtoneBytes() methods.