如何将我的 res/raw 应用程序中的 mp3 添加到 Android 铃声列表中。我不想播放它,而是将它添加到铃声列表中。一直在阅读一些主题,但仍然很困惑。
问问题
973 次
2 回答
0
如果您不介意文件被复制,那么包含它的一种简单方法是让您的应用程序将文件放在 SD 卡上:
[/sdcard]/媒体/铃声
于 2011-07-26T18:27:42.773 回答
0
只需将所有铃声添加到某个文件夹(必须先创建文件夹)
InputStream in = getResources().openRawResource(R.raw.ringtone1);
FileOutputStream out = new FileOutputStream("/mnt/sdcard/media/ringtones/ringtone1.mp3");
byte[] buff = new byte[1024];
int read = 0;
try {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
} finally {
in.close();
out.close();
}
不要忘记添加权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
如果您只想从铃声选择器中选择通知,您应该将原始 mp3 文件复制到通知文件夹。这是命名约定。然后当你像这样设置铃声选择器时
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
RingtoneManager.TYPE_NOTIFICATION);
只有当文件位于名称为通知的文件夹中时,您才会看到您的文件。
更新:
忘了说你应该在添加一些新的铃声/通知后扫描你的 SD 卡。像这样的例子:
mContext.sendBroadcast (
new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory()))
);
于 2012-11-11T15:14:47.810 回答