安卓:保存声音作为铃声和通知 [英] Android: save sound as ringtone and notification

查看:147
本文介绍了安卓:保存声音作为铃声和通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保存从我的应用程序一个声音要用作铃声或通知声音。下面是我的code,从<一个参加href="http://www.stealthcopter.com/blog/2010/01/android-saving-a-sound-file-to-sd-from-resource-and-setting-as-ringtone/"相对=nofollow>这个页面:

I'm saving a sound from my app to be used as a ringtone or a notification sound. Here's part of my code, taken from this page:

ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, soundName);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/ogg");
values.put(MediaStore.Audio.Media.ARTIST, "artist");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);

Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
this.getContentResolver().insert(uri, values);

我的理解是,声音将被保存并作为铃声,通知声音和报警器,标志都被设置为真。至少在模拟器上这样做的工作,但在实际设备上,声音只出现在铃声列表中,我不知道为什么。

My understanding is that the sound will be saved as well as a ringtone, a notification sound and an alarm, as the flags are all set to "true". At least on the emulator this does work but on the actual device, the sound only shows up in the ringtone list, and I have no idea why.

编辑:我一直在努力,深入研究:以IS_RINGTONE删除行(只有一个标志,可以在同一时间内使用的情况下)将不会改变任何东西,声音并不在列表中显示出来通知-声音。

I've tried to investigate further: removing the line with "IS_RINGTONE" won't change anything (in case only one flag can be used at a time), the sound doesn't show up in the list with the notification-sounds.

任何帮助是AP preciated。

Any help is appreciated.

亲切的问候,Select0r

Kind regards, Select0r

推荐答案

我研究了一下得到这个解决的路径,这里是我想出了迄今为止的解决方案:

I played around with the path to get this solved and here's the solution I came up with so far:

在模拟器上的路径无所谓,声音会出现在铃声和通知列表。

On the emulator the path doesn't matter, the sound will appear in the ringtone as well as the notification-list.

在电话中,声音会出现的铃声列表,如果该文件被保存到 /媒体/音频/铃声 /媒体/音频/
如果我使用的路径 /媒体/音频/通知的声音终于出现在不是作为一个通知。通知表(!),但不是在任何铃声更

On the phone, the sound will show up the the ringtone list if the file is saved to /media/audio/ringtones OR /media/audio/ but NOT as a notification.
If I use the path /media/audio/notifications the sound finally appears in the notification-list (!) but NOT in the ringtones any more.

所以,看来我要保存声音的两次的把它到这两个列表? (但为什么它保存,一旦在模拟器上工作?)

So it seems I have to save the sound twice to get it into both list? (But why does saving it once work on the emulator?)

如果有让声音进入两份名单的另一种方式(甚至三个列表,还有闹钟铃声,以及,我只是不打扰他们玩弄)只节省了他们一次,请让我知道。 (现在我的解决方法是一个对话框让用户选择是否保存声音作为铃声或通知。)

If there's another way of getting sounds into both lists (or even three lists, there are alarm tones as well, I just didn't bother playing around with them) with only saving them once, please let me know. (Right now my workaround is a dialog to let the user choose whether to save the sound as a ringtone or a notification.)

这篇关于安卓:保存声音作为铃声和通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆