Копирован исходный код android-27, похоже, что addCustomExternalRingtone
копирует выбранный вами звуковой файл, но данный параметр TYPE_ALL
не позволяет определить каталог для сохранения.
addCustomExternalRingtone
@WorkerThread
public Uri addCustomExternalRingtone(@NonNull final Uri fileUri, final int type)
throws FileNotFoundException, IllegalArgumentException, IOException {
...
// Choose a directory to save the ringtone. Only one type of installation at a time is
// allowed. Throws IllegalArgumentException if anything else is given.
final String subdirectory = getExternalDirectoryForType(type);
// Find a filename. Throws FileNotFoundException if none can be found.
final File outFile = Utils.getUniqueExternalFile(mContext, subdirectory,
Utils.getFileDisplayNameFromUri(mContext, fileUri), mimeType);
// Copy contents to external ringtone storage. Throws IOException if the copy fails.
try (final InputStream input = mContext.getContentResolver().openInputStream(fileUri);
final OutputStream output = new FileOutputStream(outFile)) {
Streams.copy(input, output);
}
// Tell MediaScanner about the new file. Wait for it to assign a {@link Uri}.
try (NewRingtoneScanner scanner = new NewRingtoneScanner(outFile)) {
return scanner.take();
} catch (InterruptedException e) {
throw new IOException("Audio file failed to scan as a ringtone", e);
}
}
И getExternalDirectoryForType
, где ошибка действительно возникает.
private static final String getExternalDirectoryForType(final int type) {
switch (type) {
case TYPE_RINGTONE:
return Environment.DIRECTORY_RINGTONES;
case TYPE_NOTIFICATION:
return Environment.DIRECTORY_NOTIFICATIONS;
case TYPE_ALARM:
return Environment.DIRECTORY_ALARMS;
default:
throw new IllegalArgumentException("Unsupported ringtone type: " + type);
}
}
Дело в том, что RingtonePickerActivity
не может решить, какой тип выбрать для сохранения, и, наконец, дать TYPE_ALL.
Похоже, вам следует переопределить точку выбора файла и передать uri и тип в RingtoneManager.addCustomExternalRingtone
или сохранить файл самостоятельно.